Dictionary and Lambdas

Why compile it:

public Dictionary<ValueLineType, 
                  Func<HtmlHelper, 
                       string, 
                       object, 
                       Type, 
                       string>> constructor = 
       new Dictionary<ValueLineType, 
                      Func<HtmlHelper, 
                           string, 
                           object, 
                           Type, 
                           string>>();

but not this other with one additional parameter in Func (boolean):

public Dictionary<ValueLineType, 
                  Func<HtmlHelper, 
                       string, 
                       object, 
                       Type, 
                       bool,  
                       string>> constructor = 
       new Dictionary<ValueLineType, 
                      Func<HtmlHelper, 
                           string, 
                           object, 
                           Type, 
                           bool, 
                           string>>();

Either I become blind, or something else that I will learn today: D

+5
source share
4 answers

There is no such thing as Func<T1,T2,T3,T4,T5,TResult>. It reaches 4 parameters (i.e. 5 type parameters, including one for the return value):

Func<T>
Func<T1, TResult>
Func<T1, T2, TResult>
Func<T1, T2, T3, TResult>
Func<T1, T2, T3, T4, TResult>
SpinalTap<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>

You can make yourself known, of course:

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

However, at this point I would think very carefully about whether you can encapsulate some of these parameters together. Are they completely unrelated?

+18
source

FYI, the next version of the .NET libraries will include the generic Func and Action types of more than four parameters.

+10

, Func, 1 5 . , 6.

+3

Func 4 , TResult

0

All Articles