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;
        }
    }
}

 

相关文章:

  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2022-02-17
猜你喜欢
  • 2022-12-23
  • 2022-02-19
  • 2021-08-04
  • 2021-10-27
  • 2021-11-20
  • 2022-12-23
  • 2021-11-08
相关资源
相似解决方案