C# Language Version

mehdi selk 1 Reputation point
2021-12-15T14:38:32.133+00:00

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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,218 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 47,806 Reputation points
    2021-12-15T15:29:07.46+00:00

    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.

    0 comments No comments

  2. Bruce (SqlWork.com) 55,196 Reputation points
    2021-12-15T15:40:01.637+00:00

    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#

    0 comments No comments

  3. Karen Payne MVP 35,031 Reputation points
    2021-12-15T17:46:29.027+00:00

    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