Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there Func objects with more than 4 parameters?

Tags:

c#

.net

I saw here that Func<(Of <(T1, T2, T3, T4, TResult>)>) Delegate was the last Func in the namespace. What do you do if you need more than 4 parameters?

like image 653
Geo Avatar asked Dec 22 '09 12:12

Geo


1 Answers

You could create your own Func delegates, or you could wait for .NET 4 to arrive (it includes built-in Func and Action delegates with up to sixteen parameters).

As others have mentioned, if you find yourself needing a delegate that takes this many parameters then maybe it's time to think about some sort of refactoring.

public delegate TResult Func<T1, T2, T3, T4, T5, TResult>
    (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);

public delegate TResult Func<T1, T2, T3, T4, T5, T6, TResult>
    (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);

public delegate TResult Func<T1, T2, T3, T4, T5, T6, T7, TResult>
    (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);

public delegate TResult Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>
    (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);

// etc
like image 199
LukeH Avatar answered Oct 06 '22 07:10

LukeH