在NET 2.0 C#3.0的兼容性

问题描述:

什么是 C#3.0 语言功能,我们可以在面向.NET 2.0框架的应用程序中使用?

What are the C# 3.0 language features we can use in an application that targets .Net 2.0 framework ?

PS:我知道一些类似的lambda EX pressions和 VAR 关键字

请在这里看到:

在.NET 2.0的应用程序使用C#3.0(.NET 3.5)语法

Using C# 3.0 (.Net 3.5) syntax in a .Net 2.0 application

对于一个完整的运行你的时候针对.NET 2.0框架和使用C#3.0和不能做什么了。

For a complete run down of what you can and can't do when targeting the .NET 2.0 Framework and using C# 3.0.

在总结:

  • You can't use the new 3.5 assemblies (System.Data.Linq, System.Xml.Linq, System.Core).
  • You can't use Linq/Query Extensions or Extension Methods (however, see below for ways to enable the use of both Linq/Query Syntax and Extension Methods!).
  • You can use the Var keyword, Lambda statements, Object Initializers, Anonymous Types & Auto-Implemented Properties.

扩展方法排序的工作,但是,他们需要System.Runtime.CompilerServices.ExtensionAttribute为了工作,该类型的System.Core程序DLL(这是不严格的.NET 2.0的部分中找到框架)。

Extension methods sort-of work, however, they require "System.Runtime.CompilerServices.ExtensionAttribute" in order to work, and this type is found within the System.Core DLL (which is not strictly part of the .NET 2.0 framework).

查询语法不能使用开箱即用,所以到说话,但是,它可以使用,如果第三方DLL(像的 LINQBridge )被使用。这个DLL有效地重新实现了许多人,你当面向.NET 2.0框架需要执行LINQ丢失的类型。它还实现所需要的扩展方法ExtensionAttribute式的工作,所以只需添加/从你的项目引用LINQBridge DLL将使LINQ,查询语法/ EX pressions和扩展方法!

Query Syntax cannot be used "out of the box" so-to-speak, however, it can be used if a 3rd party DLL (like LINQBridge) is used. This DLL effectively re-implements many of the "missing" types that you need to perform LINQ when targeting the .NET 2.0 framework. It also implements the "ExtensionAttribute" type needed for Extension methods to work, so simply adding/referencing the LINQBridge DLL from your project will enable LINQ, Query Syntax/Expressions and Extension Methods!