Mark Denom
Mark Denom

Reputation: 1057

How do I properly use C# 8 with .NET 4.0

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

Answers (1)

Jingmiao Xu-MSFT
Jingmiao Xu-MSFT

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. enter image description here

Second, add <LangVersion>8.0</LangVersion> in the code: enter image description here

Finally, reload project and add #nullable enable at the top of the file. enter image description here

Upvotes: 3

Related Questions