除了早期的 .NET 框架版本之外,Visual Studio 还可以定位早期的 C# 语法吗?
简单的部分:
使用下拉菜单在 Visual Studio 2010 项目中定位 .NET 2.0 框架。
困难的部分:
是否可以针对特定的语法版本 - 例如 var s = "hello world" 在 VS2008 及更高版本中是有效的语法糖,但在 VS2005 中无法编译。 VS2010可以配置为在编译时标记这个吗?
The easy part:
Targeting the .NET 2.0 framework in a Visual Studio 2010 project using the dropdown.
The hard part:
Is it possible to target a specific syntax version - for example var s = "hello world"
is valid syntactic sugar in VS2008 and above, but would not compile in VS2005. Can VS2010 be configured to flag this at compile time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可以通过在项目设置中指定语言版本来完成。要将语言版本设置为 C# 2.0,请执行以下
以下是 Visual Studio 2010 中的其他选择及其含义。
This can be done by specifying the language version in the project settings. To set the language version to C# 2.0 do the following
Here are the other selections and their meanings in Visual Studio 2010.
是的。从 IDE 中设置:
Yes. From the IDE, set:
是的,正如其他人所说,您可以做到这一点 - 但这并不是 C# 1 编译器的完美模拟,正如我在演讲时发现的那样。它会发现语法中的“大”变化,但不会发现行为上的一些细微变化。例如,在 C# 1 中没有方法组转换,因此您无法执行以下操作:
...但仅将 C# 4 编译器设置为目标 C# 1 并不会解决此问题。
Yes, you can do this, as others have said - but it's not a perfect simulation of the C# 1 compiler, as I discovered while I was giving a presentation. It will spot "big" changes in syntax, but not some subtle changes in behaviour. For example, in C# 1 there's no method group conversion, so you couldn't do this:
... but simply setting the C# 4 compiler to target C# 1 doesn't pick this up.