using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace cjavapy {
GPT plus 代充 只需 145class Test { delegate void MyDelegate(string s); static void MyMethod(string s) { Console.WriteLine(s); } static void Main(string[] args) { //原始委托语法 //使用指定方法初始化。 MyDelegate md1 = new MyDelegate(MyMethod); // c# 2.0:一个委托可以被初始化 //内部代码,称为“匿名方法”。这 //方法以字符串作为输入参数。 MyDelegate md2 = delegate (string s) { Console.WriteLine(s); }; // c# 3.0。委托可以被初始化 //一个lambda表达式lambda也接受一个字符串 //作为输入参数(x)。x的类型由编译器推断。 MyDelegate md3 = (x) => { Console.WriteLine(x); }; // 调用委托。 md1("C#"); md2("Java"); md3("Python"); Console.ReadKey(); } }
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/248970.html