C#中的委托范例学习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication1
{
class Program
{
public delegate void GreetingDelegate(string name); private static void GreetingPeople(string name, GreetingDelegate makingGreeting)
{
makingGreeting(name);
} private static void ChineseGreeting(string name)
{
Console.WriteLine("早上好,{0}\n", name);
} private static void EnglishGreeting(string name)
{
Console.WriteLine("Good Morning,{0}\n", name);
} static void Main(string[] args)
{
//* 调用委托方法一 *//
GreetingPeople("Shawn Chou", EnglishGreeting);
GreetingPeople("周先生", ChineseGreeting); //* 调用委托方法二 *//
GreetingDelegate delegate1;
delegate1 = EnglishGreeting;
delegate1 += ChineseGreeting;
GreetingPeople("Shawn Chou", delegate1);
Console.ReadKey();
}
}
}
上一篇:Flex4 flashVars 传值


下一篇:Hadoop MapReduce编程 API入门系列之薪水统计(三十一)