欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现的几种委托方式介绍

程序员文章站 2023-12-10 17:32:28
复制代码 代码如下://普通委托            del...

复制代码 代码如下:

//普通委托
            deleteshow ds = new deleteshow(showname);
            console.writeline("----------------------");
            console.writeline("普通委托----请输入用户名:");
            string name = console.readline();
            console.writeline(ds(name));
            console.writeline("----------------------");


//匿名方法委托

            deleteshow ds2 = delegate(string newname) {
                return string.format("匿名方法委托----输入的用户名为:{0}", newname);
            };
            console.writeline("----------------------");
            console.writeline("请输入用户名:");
            string writename = console.readline();
            console.writeline(ds2(writename));
            console.writeline("----------------------");

//lambada委托

            deleteshow ds3 = (lamname) => { return string.format("lambada委托----输入的用户名为:{0}", lamname); };
            console.writeline("----------------------");
            console.writeline("请输入用户名:");
            string writelamname = console.readline();
            console.writeline(ds3(writelamname));
            console.writeline("----------------------");