Sunday, May 1, 2011

Is there a generic system delegate that takes 2 types and returns the second

I am looking for something like Action but I want it to be

delegate U ReturnAction<T,U>(T param);

Is there already a system delegate for this? I just don't want to reinvent the wheel. I did the same thing when I first needed a Predicate and then realized it existed.

From stackoverflow
  • i think you need

    Func<T, TRet>
    

    It has various overloads

    Func<TRet>
    Func<T, TRet>
    Func<T1, T2, TRet>
    Func<T1, T2, T3, TRet>
    
    DevelopingChris : wow, I'm getting old, thats exactly what I wanted. I knew it existed but had a total brainfart.
    Jhonny D. Cano -Leftware- : jejej that was an easy one !!
  • Take a look at Func

    delegate TReturn Func<T1,TReturn>(T1 arg1);
    

    The 3.5 framework contains several overloads of func. From 0 to 4 arguments are defined.

0 comments:

Post a Comment