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:
and so on
If not, sounds like a good idea for a blog article.
Just look in the msdn database for (T) delegate.
Here you got a direct link: List of delegates
That should get you started.
I have previously blogged along these lines here. Basically, I describe how you can find an existing delegate to meet your needs using Reflector.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With