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?
views:
96answers:
3
+5
A:
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
LukeH
2009-12-22 12:29:14
.Net 4 will allow an unlimited number? By the way, can you post an example for the `Func` delegates you're talking about?
Geo
2009-12-22 12:32:25
No, not an illimited number. You can have up to 16 parameters
Thomas Levesque
2009-12-22 13:28:20
The must read book __CODE complete__ recommends up to 7 parameters. :-)
Sergey Mirvoda
2009-12-22 12:32:27
I think Steve McConnell must have had a very large monitor to read the method signatures ;) Agree wholeheartedly RE: Must Read.
Daniel Elliott
2009-12-22 12:35:33
+3
A:
In .Net 4, there's overloads till 17 (give or take) parameters.
Personally, I think that's nuts. If you need more than 4 parameters, then it's time to create a new class that has all the parameters you need as properties.
BFree
2009-12-22 12:33:14