delegate defined by .NET

  • Thread starter Thread starter RedLars
  • Start date Start date
R

RedLars

What delegate are defined by .NET ? I know of ThreadStart but I'm sure
there are others. Any reason not to use .NET delegate beyond their
original intention \ scope (given it makes sense semantically) ?
 
RedLars said:
What delegate are defined by .NET ? I know of ThreadStart but I'm sure
there are others.

There are lots of others.
Any reason not to use .NET delegate beyond their
original intention \ scope (given it makes sense semantically) ?

Not that I can think of, although what other use for ThreadStart is there
which would make semantic sense?

..NET 3.5 defines a some general purpose delegates, see:-

System.Func(TResult)
System.Func(T, TResult)
System.Func(T1, T2, TResult)
System.Func(T1, T2, T3, TResult)
System.Func(T1, T2, T3, T4, TResult)

These could save you creating lots of different delegates and/or re-using
existing delegates simply because they have the signature you need but would
be confusing if used out of context.
 
RedLars,

If you are using it for the same purpose, then yes, I would use their
delegates. Using your example, if you used the ThreadStart delegate simply
because you need a delegate that takes no parameters and returns void, then
that would be a bad choice, IMO.

But if you had a method which kicked of an action on another thread, and
you wanted to do some work before you executed the code that runs on another
thred, then the ThreadStart delegate makes a great deal of sense.

There are a number of delegates defined in the BCL for .NET, listing
them out would be counter-productive.

You should note that with the introduction of Generics in C# 2.0, the
need for specialized delegates has become very rare, given the introduction
of Action<T>, as well as Func in .NET 3.5 (and even more Action delegates in
..NET 3.5).
 
Back
Top