委托(一)C# 中委托的发展
来源:互联网 发布:签名教学软件 编辑:程序博客网 时间:2024/06/06 13:59
在 C# 1.0 中,您通过使用在代码中其他位置定义的方法显式初始化委托来创建委托的实例。 C# 2.0 引入了匿名方法的概念,作为一种编写可在委托调用中执行的未命名内联语句块的方式。 C# 3.0 引入了 Lambda 表达式,这种表达式与匿名方法的概念类似,但更具表现力并且更简练。 这两个功能统称为“匿名函数”。 通常,针对 .NET Framework 版本 3.5 及更高版本的应用程序应使用 Lambda 表达式。
下面的示例演示了从 C# 1.0 到 C# 3.0 委托创建过程的发展:
C#
class Test{ delegate void TestDelegate(string s); static void M(string s) { Console.WriteLine(s); } static void Main(string[] args) { // Original delegate syntax required // initialization with a named method. TestDelegate testDelA = new TestDelegate(M); // C# 2.0: A delegate can be initialized with // inline code, called an "anonymous method." This // method takes a string as an input parameter. TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); }; // C# 3.0. A delegate can be initialized with // a lambda expression. The lambda also takes a string // as an input parameter (x). The type of x is inferred by the compiler. TestDelegate testDelC = (x) => { Console.WriteLine(x); }; // Invoke the delegates. testDelA("Hello. My name is M and I write lines."); testDelB("That's nothing. I'm anonymous and "); testDelC("I'm a famous author."); // Keep console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }}/* Output: Hello. My name is M and I write lines. That's nothing. I'm anonymous and I'm a famous author. Press any key to exit. */
0 0
- 委托(一)C# 中委托的发展
- c# 委托(一)
- C#中委托使用一
- C#委托学习(一):C#中为什么要引入委托
- C#委托初识(一)
- C#中委托的理解
- C#中委托的演变
- c#中委托是啥样的?
- C#中委托的运用
- C#中委托的调用
- c#中委托的使用
- C#中委托的理解
- c#中委托的介绍
- C#中委托的理解
- c#委托----单一的委托
- C#委托-委托的使用
- c#中委托、事件之我见(一)
- C# 委托 学习一
- Oracle字符串处理函数
- HDu 2830 Matrix Swapping II(dp)
- oracle 过程函数,包的区别和联系
- Ubuntu 安装 subversion
- PRML 阅读笔记(七)<2.3.3-2.3.9>
- 委托(一)C# 中委托的发展
- Linux文件操作及类型详解
- Unit 5: The Writing Process
- c#如何对 Windows 窗体控件进行线程安全调用
- HDU 1398 Square Coins 母函数
- UVA - 10674-Tangents
- 第8周项目1计算函数值并输出
- C#之结构(Struct)
- 定义投影,投影转换,空间校正