question

mehdiselk-5749 avatar image
0 Votes"
mehdiselk-5749 asked PeterP-2997 commented

C# Language Version

I have a class project , and im facing the the problem of the C# language version .
I tried to udate it to version 9 or 10 but it still at 7.3
and im using visual studio 2002 by the way
i need a solution please

dotnet-csharp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


One of the solutions is probably using Visual Studio 2022.


1 Vote 1 ·

it dosent work on 2019 too

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered

Visual Studio will use the C# language as specified by the framework. This is documented here.

You can override by adding the LangVersion element to your project file. But this may or may not work. What is implemented by the compiler and what requires runtime support has been blurred. Therefore even if you get the code to compile it might not necessarily run.

Finally note that to support C# 10 you'll need to be running the version of the build that supports it which means you'll need at least VS 2022. Even if you set the lang version to a valid value if MSBuild doesn't support it because it is too old then it won't work.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork edited

C# 7.3 is the highest version supported by the 4.8 framework or .net standard 2.0. To use a later version of c# you must convert the project to .net core. To use c# 10, you need the project to be net 6

Note: this is because starting with c# 8, the compiler requires .net runtime changes for each version, so c# version and runtime are tied together.

You will need to upgrade you visual studio to use a later version of c#

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered PeterP-2997 commented

If using .NET Core you can double click on the project file in solution explorer and replace contents with

 <Project Sdk="Microsoft.NET.Sdk">
    
   <PropertyGroup>
       <LangVersion>9.0</LangVersion>
       <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
    
 </Project>

But not for a .NET Framework project e.g. 4.8

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The above can be framework project by substituting "net5.0" with "net48".
This way you can also use a different language version.



0 Votes 0 ·