一 委托的定义和调用
二 代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace CsharpConsoleApplication
{
public delegate void MyVoidDelegate();//声明一个没有参数没有返回值的委托函数
public delegate bool MyStringDelegate(string str);//声明一个参数为string类型,返回值为bool类型的委托
class Program
{
static void Main(string[] args)
{
MyVoidDelegate delvoid = new MyVoidDelegate(Who);//Who函数必须是无返回值且无参数
delvoid();//委托的调用
MyStringDelegate delstr = MyName;//MyName 函数必须是返回值为bool类型且参数是string类型
delstr("小明");//委托的调用
System.Console.ReadLine();
}
static void Who()
{
System.Console.WriteLine("我是中国人");
}
static bool MyName(string name)
{
System.Console.WriteLine("我叫"+name);
return true;
}
}
}