简体   繁体   English

使用较旧的.NET版本和较新的C#版本的副作用

[英]Sideeffects of using an older .NET version with a newer C# version

I wrote some code in .NET Project on a windows 10 machine with visual studio 2017. The target framework ist 4.5.2. 我使用Visual Studio 2017在Windows 10计算机上的.NET Project中编写了一些代码。目标框架ist 4.5.2。 and the used C# version is default (running the csc tool under "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319" shows C# 5. 并且使用的C#版本是默认版本(在“ C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319”下运行csc工具会显示C#5。

I have used a feature from C# 6. The Monadic null checking ( https://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated ). 我使用了C#6中的功能。Monadic空检查( https://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated )。 and the compiler doesn't complain about it. 并且编译器不会对此抱怨。

Is that a normal bhaviour or am I missing something? 这是正常的行为还是我缺少什么? Shouldn't the compiler complain about it? 编译器不应该抱怨吗?

What you're missing is that the C# compiler being used isn't the csc.exe you found. 您所缺少的是所使用的C#编译器不是您找到的csc.exe。 Visual Studio comes with its own C# compiler which supports C# 6 (and later, depending on the exact version of VS you've got installed). Visual Studio附带了自己的C#编译器,该编译器支持C#6(以及以后的版本,具体取决于您安装的VS的确切版本)。

C# language version is decided by Visual Studio, not by .Net Framework. C#语言版本由Visual Studio而不是.Net Framework决定。

As long as your Visual Studio version supports the C# version you will not face any error. 只要您的Visual Studio版本支持C#版本,您就不会遇到任何错误。

Configuring Language version in Visual Studio: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version 在Visual Studio中配置语言版本: https : //docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/configure-language-version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM