Using the out parameter in a Func Delegate

I have a method signature

bool TryGetItem(string itemKey,out Item item) 

How can I encapsulate this signature in

 delegate V Func<T,U,V>(T input, out U output) 

as in the message: Func <T> with out parameter ?

+6
source share
1 answer

You just wrote an answer.

If you are in .net 4.0 or higher, you can specify the variance for the parameters.

 public delegate TV MyFunc<in T, TU, out TV>(T input, out TU output); 

Then use:

 bool TryGetItem(string itemKey,out Item item); MyFunc<string, Item, bool> func = TryGetItem; 
+7
source

All Articles