Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyone know of a list of delegates already built into the framework?

Tags:

.net

I find myself writing delegates occasionally for really simple functions (take no arguments and return void for example) and am wondering if anyone knows someplace that has compiled a list of all the predefined delegates already available in the .NET framework so I can reuse them?

To be clear I am looking for something like this:

  • void System.AsyncCallback(System.IAsyncResult)
  • int System.Comparison(T x, T y)
  • void System.IO.ErrorEventHandler(object, System.Io.ErrorEventArgs)

and so on

If not, sounds like a good idea for a blog article.

like image 284
George Mauer Avatar asked Sep 15 '08 19:09

George Mauer


4 Answers

Just look in the msdn database for (T) delegate.

Here you got a direct link: List of delegates

That should get you started.

like image 71
Jorge Córdoba Avatar answered Oct 16 '22 02:10

Jorge Córdoba


I have previously blogged along these lines here. Basically, I describe how you can find an existing delegate to meet your needs using Reflector.

like image 3
Kent Boogaart Avatar answered Oct 16 '22 01:10

Kent Boogaart


One thing to keep in mind is that you write code to be readable to future coders, including your future self. Even if you can find a built-in delegate with the correct signature in the framework, it's not always correct to use that delegate if it obscures the purpose of the code.

Six months down the road, the use of a delegate of type BondMaturationAction is going to be much clearer than that of one with a type Action, even if the signatures are the same.

like image 2
Yes - that Jake. Avatar answered Oct 16 '22 02:10

Yes - that Jake.


Just use the Action, Action<T>, Action<T1,T2,..> delegates for methods not returning anything (void), or the Func<TResult>, Func<T, TResult>, Func<T1, ..., TResult> delegates for methods returning TResult.

Those delegates are new in .net 3.5.

like image 1
Thomas Danecker Avatar answered Oct 16 '22 03:10

Thomas Danecker