是否有适用于 .Net 3.5 的 C#4.0 更改列表? [英] Is there a list of changes for C#4.0 that work in .Net 3.5?

查看:12
本文介绍了是否有适用于 .Net 3.5 的 C#4.0 更改列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我看到了很多 C# 4.0 的变化.我真的很喜欢其中一些.另外,出于兼容性原因,我还不想继续使用 .Net 4.0.

I've been seeing a lot of C# 4.0 changes as of late. I really like some of them. Also though, I do not want to move on to .Net 4.0 for compatibility reasons just yet.

那么,是否有可在 .Net 3.5 或更低版本上运行的新 C# 4.0 语言功能的完整列表?

So, is there a comprehensive list of new C# 4.0 language features that will work on .Net 3.5 or lower?

例如,默认参数需要 .NET 4.0 CLR,还是编译器功能?可以使用自动属性(C# 3.0 功能)并仍然面向 .NET 2.0,因为它不需要 Framework 支持,但不能使用 LINQ 表达式,因为它需要 Framework 3.5.

As an example, do default parameters require the .NET 4.0 CLR, or are they a compiler feature? It's possible to use automatic properties (a C# 3.0 feature) and still target .NET 2.0, since that doesn't require Framework support, but not to use LINQ expressions, since that does require Framework 3.5.

请不要说当然 C#4.0 不能在 .Net 3.5 中工作,因为它更旧了"

Please don't say "of course C#4.0 won't work in .Net 3.5 cause it's older"

推荐答案

4.0 中的 C# 编译器带有新的多目标功能.简而言之,它将生成一个程序集,其中包含定义 System.Object(通常是 mscorlib.dll)的引用中存在的任何元数据版本.这允许您使用它来为 2.0 和 3.5 以及各种版本的 Silverlight 编译程序集.引入此功能是为了支持 Visual Studio 2010 中的多目标.

The C# compiler in 4.0 ships with a new multitargeting feature. The short version is that it will produce an assembly with whatever metadata version is present in the reference that defines System.Object (usually mscorlib.dll). This allows you to use it to compile assemblies for 2.0 and 3.5, as well as various versions of Silverlight. This feature was introduced in support of the multitargeting in Visual Studio 2010.

因此,您可以使用 C# 4.0 编译器来编译 3.5 程序集,并使用您想要的任何 C# 4 功能,只要对 4.0 库没有特别的依赖性.例如,命名参数和可选参数可以正常工作,因为它们不使用任何 4.0 框架功能.但是,Dynamic 可以,因此开箱即用,它不适用于 3.5.

Therefore, you can use the C# 4.0 compiler to compile 3.5 assemblies, and make use of whatever C# 4 features you want, so long as there is no particular dependency on 4.0 libraries. For example, named arguments and optional parameters will work fine, because they don't use any 4.0 framework features. Dynamic, however, does, and so out of the box it won't work on 3.5.

这里有一篇关于此的帖子,涵盖了基础知识.

There is a post about this here, that covers the basics.

http://blogs.msdn.com/ed_maurer/archive/2010/03/31/multi-targeting-and-the-c-and-vb-compilers.aspx

短名单(来自 Ed 的帖子)是:

The short list (from Ed's post) is:

  • 命名参数和可选参数
  • 某些 COM 语法改进(例如,省略引用")
  • 通用方差

行不通的事情包括动态和无pia(就实施它们所花费的时间而言,这是我们最大的两项支出).前者需要框架支持,后者需要运行时支持.

Things that won't work include dynamic and no-pia (our two biggest outlays in terms of time spent implementing them). The former requires framework support and the latter requires runtime support.

这篇关于是否有适用于 .Net 3.5 的 C#4.0 更改列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆