In the Properties for the project, what setting do you have here?
Build->Advanced->Language version
- Wayne
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I currently use Visual Studio 2019 build 16.8.3. I understand that C# 9.0 features should be available on that platform now. However, if I try to declare a 'record' type in Visual Studio, it shows an error. For example:
namespace Records
{
public record Person
{
}
} // namespace Records
It shows squiggly red lines under 'record' and 'person'. The record error is CS0246: The type or namespace name 'record' could not be found... The Person error is CS0116: A namespace cannot directly contain members such as fields or method and CD0548: '<invalid-global-code>.Person': property or indexer must have at least one accessor.
How do I get Visual Studio to recognize and use C# 9.0 features?
Thanks.
In the Properties for the project, what setting do you have here?
Build->Advanced->Language version
It won't let me change the 'Language version'. Says: Automatically selected based on framework version. I edited the .csproj file to change the framework version from 'netcoreapp3.1' to 'netcoreapp5.0' and that fixed the problem. Thanks for the help.
For SDK Style projects <LangVersion> can be set to latest as below in csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>
Sorry, I solved this problem a few months ago. We can close this question.