public delegate double DelegateCompute(double x); namespace WindowsFormsApplication2 { class MoneyCompute { public static double Compute(double t, DelegateCompute dc) { return dc(t); } public MoneyCompute() { } } } public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static double Low(double x) { return x * 0.02; } public static double High(double x) { return x * 0.1; } private void button1_Click(object sender, EventArgs e) { double result; DelegateCompute dc; dc = new DelegateCompute(Form1.Low); result = MoneyCompute.Compute(1000, dc); label1.Text = result.ToString(); dc = new DelegateCompute(Form1.High); result = MoneyCompute.Compute(200, dc); label2.Text = result.ToString(); } } using System; using System.Collections.Generic; using System.Linq; using System.Text; public delegate void Message(); namespace WindowsFormsApplication1 { class Messages { public static void Greeting() { Console.WriteLine("welcome to Webcast and MSDN China"); } public static void DateAndTime() { Console.WriteLine(DateTime.Now.ToLongDateString()); } public static void FeedBack() { Console.Write("Your feedback are very important to us"); } } } namespace WindowsFormsApplication1 { public partial class Form1 : Form { Message msg; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { msg = new Message(Messages.Greeting); msg += new Message(Messages.DateAndTime); msg(); } } }
posted on 2010-05-13 19:50 java课程设计 阅读(201) 评论(0) 收藏 举报