2015-06-23 16 views

Odpowiedz

9

tak (za pomocą lambda expression):

var properties = new List<Tuple<string, string, Func<bool>>> 
{ 
    Tuple.Create<string, string, Func<bool>>(
       FirstName, 
       "User first name is required", 
       () => FirstName == null), 
}; 
6

coś takiego:

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, string, Func<bool>>> 
{ 
    Tuple.Create(FirstName, "User first name is required", new Func<bool>(() => FirstName == null)), 
}; 

Należy zauważyć, że istnieją pewne limitatons aby wpisać wnioskowanie do wyrażenia lambda ... z tego powodu new Func<bool> stosuje się sposób budowania delegata.

Alternatywy:

Tuple.Create(FirstName, "User first name is required", (Func<bool>)(() => FirstName == null)), 
Tuple.Create<string, string, Func<bool>>(FirstName, "User first name is required",() => FirstName == null), 
new Tuple<string, string, Func<bool>>(FirstName, "User first name is required",() => FirstName == null), 

w końcu trzeba repeate się Func<bool> gdzieś.

Powiązane problemy