ERORR CS8370 VISUAL STUDIO C#

Andreea PUPĂZAN (111294) 1 Reputation point
2022-02-26T19:06:14.08+00:00

Hello! I'm working on a project in visual studio 2019 in C#
The target framework is : .NET Framework 4.7.2

The problem is I have this erorr:
"CS8370: Feature 'top-level statements' is not available in C# 7.3. Please use language version 9.0 or greater."

What could I do to solve it ?

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,390 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,201 Reputation points
    2022-02-26T19:34:02.69+00:00

    You need to be using C#9 or higher and .NET Framework Core 5 or 6.

    See my repository for examples which are done in VS2019, work also in VS2022.

    The project file will need

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

    See also C# language versioning and Explore ideas using top-level statements to build code as you learn

    1 person found this answer helpful.
    0 comments No comments