源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#中使用委托的3种方式代码示例

  • 时间:2020-11-15 23:16 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#中使用委托的3种方式代码示例
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;
    }
  }
}
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部