关闭

delegate 委托一例

标签: stringclass
546人阅读 评论(0) 收藏 举报
分类:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTest
{
    class delegateTest
    {

        public delegate void GreetingDelegate(string sName);
        public static void GreetingPeople(string sName, GreetingDelegate delegateGreeting)
        {
            delegateGreeting(sName);
        }

        public static void EnglishGreeting(string sName)
        {
            Console.WriteLine("Good morning," + sName);
        }

        public static void ChineseGreeting(string sName)
        {
            Console.WriteLine("早上好," + sName);
        }

        //public enum Language
        //{
        //    English,
        //    Chinese
        //}

        //public void GreetingPeople(string sName,Language lang)
        //{
        //    switch (lang)
        //    { 
        //        case Language.Chinese:
        //            ChineseGreeting(sName);
        //            break;
        //        case Language.English:
        //            EnglishGreeting(sName);
        //            break;
        //    }
        //}

        static void Main()
        {
            GreetingPeople("Von Super", EnglishGreeting);
            GreetingPeople("罗导",ChineseGreeting);
            Console.WriteLine("先埋头,再出头!");
            Console.WriteLine("仰天长啸出门去,我辈岂是蓬蒿人!");
            Console.ReadLine();
        }

    }
}


运行结果:

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2540727次
    • 积分:22144
    • 等级:
    • 排名:第316名
    • 原创:587篇
    • 转载:69篇
    • 译文:0篇
    • 评论:364条