C#委托
delegate void Do(int sleepSpan);
//typedef void (*Fun)(int sleepSpan); C++
namespace ConsoleApplication1
{
class Program
{
public static void DoSomeThing(int sleepSpan)
{
DateTime dt = DateTime.Now;
System.Console.WriteLine(dt.ToString());
System.Threading.Thread.Sleep(sleepSpan);
}
public static void Loop(int sleepSpan,string title,Do doSome /*Fun fun C++*/)
{
System.Console.WriteLine("开始{0}了", title);
//Do dost = new Do(doSome);
Do dost = doSome;
while (true)
{
dost(sleepSpan);
//fun(sleepSpan); C++
}
}
static void Main(string[] args)
{
Loop(1000,"显示时间",DoSomeThing);
}
}
}
1.与C++函数指针类似