Reputation: 1057
So I'm trying to utilize C# 8 in my .NET 4 web application by adding two entries in my .csproj
file right inside the PropertyGroup
node.
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
But for some reason when I try to do string? name = "";
I still get an error stating "Error CS8370 Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater."
I'm using Visual Studio 2022 17.0.4.
Why is it that I get this error?
Upvotes: 6
Views: 5455
Reputation: 2297
If you want to use nullable reference types in .NET 4.0 web application, you can refer to the following steps: First, unload your project, right-click and choose Edit Project File to open .csproj file.
Second, add <LangVersion>8.0</LangVersion>
in the code:
Finally, reload project and add #nullable enable
at the top of the file.
Upvotes: 3