using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Collections; using System.Drawing; using System.Linq; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Workflow.Runtime; using System.Workflow.Activities; using System.Workflow.Activities.Rules; namespace wfConsole { delegate void PrintLine(); delegate void PrintContent(string s, int count); public sealed partial class Workflow1 : SequentialWorkflowActivity { public Workflow1() { InitializeComponent(); } private void ReviewDelegate_ExecuteCode(object sender, EventArgs e) { // 委派 C# 1.0 PrintLine pl = new PrintLine(this.WriteLine); PrintContent pc = new PrintContent(this.WriteContent); pl.Invoke(); pc.Invoke("C# 1.0", 5); // 委派 C# 2.0 PrintLine pl2 = delegate() { Console.WriteLine("********************"); }; PrintContent pc2 = delegate(string s, int count) { for (int i = 0; i < count; i++) { Console.Write("{0:00} ", i + 1); Console.WriteLine(s); } }; pl2.Invoke(); pc2.Invoke("C# 2.0", 5); // 委派 C# 3.0 PrintLine pl3 = () => { Console.WriteLine("----------------------"); }; PrintContent pc3 = (string s, int count) => { for (int i = 0; i < count; i++) { Console.Write("{0:00} ", i + 1); Console.WriteLine(s); } }; pl3.Invoke(); pc3.Invoke("C# 3.0", 5); Console.Read(); } private void WriteLine() { Console.WriteLine("========================="); } private void WriteContent(string s, int count) { for (int i = 0; i < count; i++) { Console.Write("{0:00} ", i + 1); Console.WriteLine(s); } } } }
2010/02/15
review : delegate in c#
I think I've got old because while using delegate, I couldn't remember it's usage. So I think it's a good idea to take a review and memo it here.