While we’re on the subject of conveniences, C# 3.0 also introduces two new features that help when instantiating and initializing object instances. Using object and collection initializers, you can instantiate and initialize either an object or a collection in one compound statement.
Extension methods are one of the most exciting new features. Taken from the surface view, they are merely static methods that can be called as if they were instance methods. They do not get any special access into the instance they are operating on, so in that respect, they are just like static methods. However, the syntax they foster allows us to program in a more functional manner, usually resulting in clearer and more readable code.
Probably more compelling than extension methods is support for lambda expressions. Lambda expressions supersede support for anonymous methods. That is, if lambda expressions had existed in C# 2.0, there would have been no need for anonymous methods at all. However, lambda expressions offer much more than anonymous methods as they can be converted into both delegates and expression trees. The granddaddy of all new C# 3.0 features has to be LINQ, which builds upon all of the new features, especially extension methods, lambda expressions, and anonymous types. It also adds some new language keywords to allow us to code intuitive query statements, thus seamlessly bridging the gap between the object-oriented world and the data world. You can use LINQ to access data from multiple sources. Visual Studio provides the capability to use LINQ on native object collections, SQL data stores, and XML. Support for many other data sources is coming soon from both Microsoft and third parties. For example, you’ll be able to use LINQ to connect to Windows Management Instrumentation (WMI), the Document Object Model (DOM), and the Web. Additionally,there are implementations in the works to use LINQ against popular web sites such as Google and Flickr.
B.原文的翻译
对C# 2.0和C# 3.0的新功能概述
2000年底发布了C#语言,C#逐步被熟知和认可,发展势头迅猛。随着Visual Studio 2005和.NET Framework2.0的发布,C#编译器实现了对C# 2.0增强功能的语言支持。因此C# 2.0更先进,它提供了一个更自然的编程环境,而且大大提高工作效率。论文网
C# 2.0中丰富了的更新内容,它是对泛型的支持。其语法和C++模板相似,但两者主要区别是,在.NET泛型创建的构造类型为动态,在运行运行时构建。而C++是由模板创建的具体类型,为静态,在编译时创建它们的约束。
C#中的容器类型如矢量、哈希表,使用泛型可以提供最大的效率增益,该方法很可行。泛型不是使用的所有对象,它们包含特别的类型,而并非是使用所有对象的基类System.Object。
C#的匿名方法对委托及事件帮助性很大。委托及事件是用来触发注册,称作回调方法的构建,常常被连接到定义方法的地方。对于匿名方法,可以定义事件或委托的代码内联,在事件或委托中进行设置。这方便可行,若代理仅需要执行少量的工作,就不必定义其整个方法。而且,匿名方法体可以对范围在一点上是defined.Lambda的所有表达式变量进行访问,这是C# 3.0可以实现的新功能,是更可读的代码。 对C# 2.0和C# 3.0的新功能概述英文文献和中文翻译(2):http://www.youerw.com/fanyi/lunwen_40653.html