委托(五):多播委托

来源:互联网 发布:如何用c语言编写程序 编辑:程序博客网 时间:2024/06/04 18:23

一  :显示效果

二 :代码

using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Security.Cryptography;using System.Text;namespace ConsoleApplication1{           class Program    {        public delegate bool MyDelegate(string str);        static void Main(string[] args)        {            MyDelegate del = FunOne;            del += FunTwo;//增加执行FunTwo()函数            del += FunThree;//增加执行FunThree()函数            del -= FunTwo;//不执行FunTwo()函数            del("委托");//会执行FunOne()和FunThree()两个函数            System.Console.Read();        }        static bool FunOne(string str)        {            System.Console.WriteLine(str+" One");            return true;         }        static bool FunTwo(string str)        {            System.Console.WriteLine(str + " Two");            return true;        }        static bool FunThree(string str)        {            System.Console.WriteLine(str + " Three");            return true;        }         }    }


0 0
原创粉丝点击