Lambda expressions and expression trees

1. introducing the Func<…> delegate types

  Here are the signatures
of all the Func delegate types:
public delegate TResult Func<TResult>()
public delegate TResult Func<T,TResult>(T arg)
public delegate TResult Func<T1,T2,TResult>(T1 arg1, T2 arg2)
public delegate TResult Func<T1,T2,T3,TResult>
(T1 arg1, T2 arg2, T3 arg3)
public delegate TResult Func<T1,T2,T3,T4,TResult>
(T1 arg1, T2 arg2, T3 arg3, T4 arg4)

Func<string,double,int> is equivalent to a delegate type of the form
delegate int SomeDelegate(string arg1, double arg2)

 

Func<string> returnHello;
            Func
<stringstring> returnContent;
            Func
<stringint> returnLength;

            returnHello 
= () => { return "Hi David!"; };
            returnContent 
= (string text) => { return text; };
            returnLength 
= (string text) => { return text.Length; };

            Console.WriteLine(returnHello());
            Console.WriteLine(returnContent(
"Hi David!"));
            Console.WriteLine(
"Length of content: " + returnLength("Hi David!"));

 

技术改变世界
原文地址:https://www.cnblogs.com/davidgu/p/2174132.html