Func for 5 arguments

I work with System.Func, but I ran into a stumbling block.

System.Func<TReturn> // (no arg, with return value)
System.Func<T, TReturn> // (1 arg, with return value)
System.Func<T1, T2, TReturn> // (2 arg, with return value)
System.Func<T1, T2, T3, TReturn> // (3 arg, with return value)
System.Func<T1, T2, T3, T4, TReturn> // (4 arg, with return value)

The maximum number of accepted values ​​is 4 arguments.

Is there a way to expand this to 5 arguments?

+1
source share
3 answers

You have several options: define a delegate that will look like this:

public delegate TResult Func<T1,T2,...,TN,TResult>(T1 arg1, T2 arg2,...,TN argN); 

you can basically define it for any number of arguments (more than 4, because otherwise you may come across a name)

or you can wrap your arguments in some kind of structure so that you can use one of the Func delegates already defined for you.

, Func. - , , ( ) .

, , , , , , ( Func , , , )

+5

I think you can see Action and Func with at least 25 parameters in the 5.0 framework :)

There is no reason to upgrade to a version with a higher version, because I cannot convert my code into a valid, supported view. Indeed, it is not a good practice to use so many parameters in a function signature method. Use an object that has 5 fields or properties. You can expend this object without changing the method or function signature.

+1
source

All Articles