I just started my first project with c#8 and immediately I'm hit with warnings everywhere on my properties. After some research, it looks like I'm now supposed to explicitly add a ? to any properties that can be null.
Two questions:
If I port code from previous versions to this version, does this actually affect runtime in anyway whatsoever, or do I just have to ignore a bunch of warnings?
Is there a simple switch to revert to the old behavior so it won't show these warnings? I understand that there are ways I could update my code in a million places to ignore the warnings... I don't want to do that. It's a waste of time and I'd rather live with them if they don't actually affect anything at runtime. But if there is something I can do in a single place to get rid of them that would be great.
<Nullable>disable</Nullable>
in the project file or #nullable disable
at the top of your source file will do it.example .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <!-- this -->
<AssemblyTitle>whatever....</AssemblyTitle>
</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