Reputation: 28265
I find myself quite often writing delegates that take common arguments or return types. As such I often find myself using delegates like this:
public delegate void CommonVoidEmptyDelegate();
public delegate void CommonVoidDelegate<TParam>(TParam p);
public delegate void CommonVoidParamDelegate<TParam>(params TParam[] p);
public delegate TReturn CommonEmptyDelegate<TReturn, TParam>(TParam p);
public delegate TReturn CommonParamDelegate<TReturn, TParam>(params TParam[] p);
Instead of me defining these in each project I would like to know if there's something common in the framework that I can use.
Upvotes: 1
Views: 72
Reputation: 68710
You can use Action
, Action<T>
for the first two, and Func<T, TResult>
for the third one.
There is no standard delegate for the 3rd and 5th delegates.
Upvotes: 3
Reputation: 13248
Converting comment to answer:
just use Func
and Action
delegates. They provide a great deal of flexibility.
Upvotes: 3
Reputation: 169268
You're probably looking for the Action
and Func
families of delegates.
Upvotes: 7