using System;using System.Windows.Forms; namespace Test{ public delegate void FeedBack(string str); public class Test { [STAThread] static void Main(string[] args) { FeedBack feedBack = null; feedBack += new FeedBack(FeedBackToConsole); feedBack += new FeedBack(FeedBackToMsgBox); ProcessFeedBack(feedBack); feedBack -= new FeedBack(FeedBackToConsole); ProcessFeedBack(feedBack); Console.ReadLine(); } static void ProcessFeedBack(FeedBack feedBack) { if (feedBack != null) feedBack("hello"); } static void FeedBackToConsole(string str) { Console.WriteLine(str); } static void FeedBackToMsgBox(string str) { MessageBox.Show(str); } }}
Delegate揭秘
最新推荐文章于 2019-10-03 22:23:32 发布