using System;
namespace ConsoleApp1
{
// 定義一個(gè)委托
public delegate int Delegate(int i);
class Program
{
static void Main(string[] args)
{
Program p = new Program();
Delegate d1 = p.Calc;
Console.WriteLine($"完整函數(shù)調(diào)用:{d1(10)}");
Delegate d2 = delegate (int i) { return i * i; };
Console.WriteLine($"匿名函數(shù)調(diào)用:{d2(10)}");
Delegate d3 = (int i) => i * i;
Console.WriteLine($"Lambda表達(dá)式調(diào)用:{d3(10)}");
}
// 自定義函數(shù)堤框,計(jì)算參數(shù)的平方
public int Calc(int i)
{
return i * i;
}
}
}
運(yùn)行結(jié)果