zoukankan      html  css  js  c++  java
  • Net中委托之二多播委托

    本篇主要讲解多播委托

    1.多播委托的实例

     public class MyDelegate
        {
            private delegate int NoParameterWithReturn();//1.声明委托
            public static void Show()
            {
                NoParameterWithReturn method = new NoParameterWithReturn(ShowSomething);//2.委托的实例化
                //多播委托
                method += ShowSomething;//按顺序添加到方法列表
                method += ShowSomething;
                method += ShowSomething;
                method += ShowSomething;
                method -= ShowSomething;//从方法列表的尾部去掉且只去掉一个完全匹配
                Console.WriteLine("method.Invoke()结果是{0}", method.Invoke());//3.委托实例的调用
            }
            private static int ShowSomething()
            {
                Console.WriteLine("这里是ShowSomething");
                return 11;
            }
        }
     class Program
        {
            //多播委托
            static void Main(string[] args)
            {
                Console.WriteLine("欢迎来到流星小子博客学习");
                MyDelegate.Show();
                Console.Read();
            }
        }

    2.运行结果

  • 相关阅读:
    poj3253Fence Repair (Huffman)
    poi3617Best Cow Line ——贪心法
    高级排序之——归并排序
    Aizu
    初级排序——冒泡排序
    cookie会话
    加载web资源文件
    servlet
    Http

  • 原文地址:https://www.cnblogs.com/gylhaut/p/5785465.html
Copyright © 2011-2022 走看看