zoukankan      html  css  js  c++  java
  • C#1到C#4使用委托的几种方式

    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;
            }
        }
    }
  • 相关阅读:
    方法的重载
    this用法
    简单的随机数 代码和笔记
    java内存简单剖析
    day 28
    day 27
    day 26
    day 25
    day 24
    day 23
  • 原文地址:https://www.cnblogs.com/DoNetCoder/p/4304681.html
Copyright © 2011-2022 走看看