C#中使用委托的3种方式代码示例_C#教程-查字典教程网
C#中使用委托的3种方式代码示例
C#中使用委托的3种方式代码示例
发布时间:2016-12-28 来源:查字典编辑
摘要:usingSystem;namespaceDelegateDemo{classProgram{privatedelegateintCacu(...

using System; namespace DelegateDemo { class Program { private delegate int Cacu(string str); static void Main(string[] args) { //1 Cacu cacu = new Cacu(CacuInstance); Console.WriteLine(cacu("Hello,Wrold")); //2 Cacu cacu1 = new Cacu(delegate(string str) { return str.Length; }); Console.WriteLine(cacu1("Hello,Wrold")); //3 Cacu cacu2 = new Cacu((str) => { return str.Length; }); Console.WriteLine(cacu2("Hello,Wrold")); } static int CacuInstance(string str) { return str.Length; } } }

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类