添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

  • Wayne
  • 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>