c# 多播委托 和匿名方法
2010-02-21 15:41
363 查看
using System; using System.Collections.Generic; using System.Text; namespace threadserver_c { delegate void StrMod(ref string str); class DelegateTest { public void replaceSpaces(ref string a) { System.Windows.Forms.MessageBox.Show("Replaces spaces with hyphens."); a= a.Replace(' ', '-'); } public void removeSpaces(ref string a) { string temp = ""; int i; System.Windows.Forms.MessageBox.Show("Removing spaces."); for (i = 0; i < a.Length; i++) { if (a[i] != ' ') temp += a[i]; } a= temp; } static string reverse(string a) { string temp = ""; int i, j; System.Windows.Forms.MessageBox.Show("reversing string."); for (j = 0, i = a.Length - 1; i >= 0; i--, j++) { temp += a[i]; } return temp; } } } private void Form1_Load(object sender, EventArgs e) { DelegateTest a = new DelegateTest(); StrMod strop; StrMod replaceSp= a.replaceSpaces; StrMod removeSp = a.removeSpaces; string str="This is a test."; strop = replaceSp; strop += removeSp; strop(ref str ); MessageBox.Show(str); } private void button1_Click(object sender, EventArgs e) { CountIt count = delegate { for (int i = 0; i < 5; i++) this.Text = i.ToString (); }; count(); }
相关文章推荐
- C#中的委托,匿名方法和Lambda表达式
- C# 委托 事件 匿名方法
- C#中的委托,匿名方法和Lambda表达式
- C# 从CIL代码了解委托,匿名方法,Lambda 表达式和闭包本质
- C#中的委托,匿名方法和Lambda表达式(转载)
- 编写高质量代码改善C#程序的157个建议[为泛型指定初始值、使用委托声明、使用Lambda替代方法和匿名方法]
- C#匿名方法增加、删除委托
- C# 匿名方法和拉姆达表达式 (2012-04-27 23:27:15)转载▼ 标签: 杂谈 匿名方法本质上是一传递给委托的代码块,是使用委托的另一种方法。 规则: 1、匿名方法中不能使用跳转语句跳
- C# 委托、匿名方法、Lamabda 表达式
- C#中使用委托、接口、匿名方法、泛型委托实现加减乘除算法
- c# 中的委托以及匿名方法lambda
- C#中使用委托、接口、匿名方法、泛型委托实现加减乘除算法
- C#中委托的匿名方法,及其在协变与逆变中的应用
- C#学习之初步理解委托、事件、匿名方法和Lambda
- C#委托基础7——匿名方法
- c# 匿名方法(委托)
- C# 入门(9) 委托(delegate),匿名方法,Lambda表达式
- C#学习之初步理解委托、事件、匿名方法和Lambda
- c# 匿名方法(委托)
- C#笔记 委托 事件 匿名方法 Action