• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
日出而作,日落而息,何必想太多.......
人生,还不如一张白纸来的自由。 Themusic.kh
博客园    首页    新随笔    联系   管理    订阅  订阅
委托、匿名方法和 Lambda 表达式

/// <summary>
    /// ProgramName:委托、匿名方法和 Lambda 表达式
    /// </summary>
    class Program
    {

        //C#1.0  Delegate Declare
        delegate string MyTestC1(string str);

        //C#2.0  Delegate Declare
        delegate string MyTestC2(string str);

        //C#3.0  Delegate Declare
        delegate string MyTestC3(string str);

        static void Main(string[] args)
        {
            Program classP=new Program();
            classP.C1Function();
            classP.C2Function();
            classP.C3Function();
        }

        //C#1.0  Delegate Function
        string MyFunction(string str)
        {
            return "C#1.0 -> " + str;
        }

        //C#1.0  Delegate Transfer
        void C1Function()
        {
            Program classP = new Program();
            MyTestC1 c1 = classP.MyFunction;
            Console.WriteLine(c1("Hello Word!"));
        }

        void C2Function()
        {
            //C#2.0  Delegate Function
            MyTestC2 c2 = delegate(string str)
            {
                return "C#2.0 -> " + str;
            };

            //C#2.0  Delegate Transfer
            Console.WriteLine(c2("Hello Word!"));
        }

        void C3Function()
        {
            //C#3.0  Delegate Function
            MyTestC3 c3 = ((str) => "C#3.0 -> " + str);
            //C#3.0  Delegate Transfer
            Console.WriteLine(c3("Hello Word!"));
        }

    }

posted on 2009-08-27 13:33  /Themusic.kh  阅读(203)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3