zoukankan      html  css  js  c++  java
  • action委托的使用

    类文件中:

     public class greeting
        {
         
    
    
            public void sayhiEnglish(string name)
            {
                Console.WriteLine("hello world,{0}",name);
    
            }
    
            public void sayhiChinese(string name)
            {
                Console.WriteLine("good morning,{0}", name);
    
            }
    
            public void sayhiAmerican(string name)
            {
                Console.WriteLine("merry christmas,{0}", name);
    
            }
    
            public void sayhiET(string name, peopletype type)
            {
                Console.WriteLine("%$^&**,{0}", name);
    
            }
    
    
            public void sayhidelegate(string name,Action<string> act)
            {
                Console.WriteLine("*********");
                act.Invoke(name);
                Console.WriteLine("结束时间"+DateTime.Now+"");
            }
    
    
    
    
    
    
        }

    program.cs文件中:

     greeting g = new greeting();
                Action<string> act = g.sayhiAmerican;
                g.sayhidelegate("1998",act);
                g.sayhidelegate("小明",new Action<string>(g.sayhiChinese));

    一般委托的使用:委托使用必须保证参数和返回值相同

     public delegate string fly(int a);
     static void Main(string[] args)
            { fly f = new fly(gh);
    
                Console.WriteLine(f(10));
            }
     public static string gh(int s)
            {
                return (s + 10).ToString();
            }
  • 相关阅读:
    如何学习linux编程
    SharpMap学习9调侃WebGIS
    蛮力法01
    SharpMap学习10比例尺
    蛮力法03
    系统学习Linux11点建议
    蛮力算法02
    大地坐标系
    Windows 7下删除右键新建菜单项的多余选项
    GIS中的坐标系相关概念
  • 原文地址:https://www.cnblogs.com/wy1992/p/7490043.html
Copyright © 2011-2022 走看看