I try to use the newest C# 10 features in Visual Studio 2022 Preview 3. The compiler does not recognize the new keywords required or field. global using seems to work.
public required string Name { get; init; }
public DateTime HiredDate{ get; init => field = value.Date(); }
Null parameter checking doesn't compile:
public void NullParameterCheck(string arg!!) { ... }
I also tried to set the language version to preview in the .csproj:
<LangVersion>preview</LangVersion>
Is there any setting I missed?
Finally I found part of the solution. I have to add
<LangVersion>preview</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
to the .csproj file. Null parameter checks work, but not required and field.
this is what I use in .csproj file:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<GenerateRequiresPreviewFeaturesAttribute>true</GenerateRequiresPreviewFeaturesAttribute>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With