Reputation: 6289
In Visual Studio 2019 I can set the Nullable Option in the Build-Properties to Annotation. When I read in the docs for this settings:
Variables of a reference type, string for example, are non-nullable. All nullability warnings are disabled.
Now I wonder what the exact use of this setting is. The variables are non-nullable, but there are no warnings. The Non-Nullable-Feature of C# 8 only generates warnings. Why is there a setting which says the variables are non-nullable but there are no warnings?
Upvotes: 2
Views: 2408
Reputation: 5003
The #nullable enable annotations
directive and the corresponding project setting are useful to add annotations to a public API before being ready to deal with warnings in your code.
In such a nullable context, string
means "not-nullable string", but no warnings are produced if you assigned null to a variable of that type or if you dereference a variable of type string?
.
Upvotes: 2