简体   繁体   中英

Can i use C# 11 features in .NET 6?

I'm studying the new features about C# 11 and i don`t know if i can use it with .NET 6.0 or only in .NET 7.0.

I also saw that i can lock the version of C# like this:

<PropertyGroup>
   <LangVersion>11</LangVersion>
</PropertyGroup>

Is there a good practice locking the version? Thinking that if there's a new feature in the language it can brake my application. Or just let it with latest is good enough?

The official blog - Early peek at C# 11 features - states:

Visual Studio 17.1 (Visual Studio 2022 Update 1) and .NET SDK 6.0.200 include preview features for C# 11! You can update Visual Studio or download the latest .NET SDK to get these features.

(...)

Your .csproj file might look like:

 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <LangVersion>preview</LangVersion> </PropertyGroup> </Project>

Using the latest version of the language and its preview features for studying is completely fine! (For production code it's nuanced.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM