6

I tried installing .net framework 4.7.2, still the target framework is empty in the project properties. The program I'm trying to run uses readonly struct, which is part C# 7.2.

Could you please guide me .Net Framework version has C# 7.2?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Pandiarajan
  • 410
  • 5
  • 14

2 Answers2

13

Language features are independent of .Net version (Framework/Core/Standard).

You will need to use a compiler that understands the newer language features. Assuming you're using Visual Studio 2017, you should update to latest version.

phuzi
  • 12,078
  • 3
  • 26
  • 50
  • I have VS 2017 fully updated, but C# 7.2 is not seen as default target language. @Joe Sewell's answer is the right one. – lmsasu Mar 18 '19 at 06:50
  • This answer is correct. The question asks the .net framework version that c#7.2 needs. But in fact c#7.2 doesn't require any framework version. As long as you have the libraries that the new features need (via source or nuget), you are able to compile even using 4.5 runtime. The answer to the title is not about visual studio. – joe May 02 '19 at 04:47
7

By default C# projects in Visual Studio use the latest major release of the language (which would be 7.0 as of this writing). To change this, open up the project's properties, select the Build page, click Advanced..., and under General set Langauge Version to "C# 7.2".

Per phuzi's comment mentioning this question, you might need to update to the latest Visual Studio in order to see this option.

Joe Sewell
  • 6,067
  • 1
  • 21
  • 34
  • Tried this in VS 2019, and the option is grayed out, and defaulted to, "Automatically selected based on framework version." There is a help reference to: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version For more information on why you can't change the version through the UI. – eaglei22 Jul 13 '20 at 13:27