3

I wrote some code in .NET Project on a windows 10 machine with visual studio 2017. The target framework 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.

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). 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?

mh133
  • 135
  • 12
  • change your .NET version 4.5.2 to 4.5 – Udara Kasun Sep 13 '18 at 10:02
  • 1
    There are already ansewers, it's not directly related but when in doubt on C# version, this post is a good reminder: https://stackoverflow.com/questions/247621/what-are-the-correct-version-numbers-for-c – Mikitori Sep 13 '18 at 10:05
  • 2
    Many language features in newer C# compilers only require the compilers themselves, so they can be used even if you target an old .NET Framework release. That's exactly what we call multi targeting. Remind you that recent C# compiler releases are independent of .NET Framework releases, https://blog.lextudio.com/the-rough-history-of-the-so-many-c-compilers-f3a85500707c – Lex Li Sep 13 '18 at 23:46
  • @UdaraKasun can I ask why? what is the benefit of that? – Norbert Forgacs Dec 09 '21 at 08:04

2 Answers2

3

What you're missing is that the C# compiler being used isn't the csc.exe you found. 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).

0

C# language version is decided by Visual Studio, not by .Net Framework.

As long as your Visual Studio version supports the C# version you will not face any error.

Configuring Language version in Visual Studio: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

Carbine
  • 7,849
  • 4
  • 30
  • 54