using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication17
{
public delegate string testDelegate(string a, int b);
class Program
{
static void Main(string[] args)
{
//1 C# 1 最原始的委托赋值
testDelegate t1 = new testDelegate(M);
//2 C# 2 委托赋值
testDelegate t2 = delegate (string a, int b)
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
};
//3 C# 3 委托赋值(a,b值类型对应委托声明的类型)
testDelegate t3 = (a, b) =>
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
};
// 调用委托实例
t1.Invoke("测试1", 665);
t2.Invoke("测试2", 666);
t3.Invoke("测试3", 667);
}
static string M(string a, int b)
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
}
}
}
![]()