C#C
C#4y ago
Puck

Nullable strings in .net 6

So I'm a little bit new to .NET 6 coming from .NET framework.

Do we have to make a
string
string?
in .NET6 and above if it's nullable or can we ignore it? Say I have a parameter
void Foo(string str = null)
, I get warned by rider because it says it's a null literal in a non-nullable reference type but it compiles just fine. Is it best practice to have the strings declared like
string?
when nullable

So in the end, we use
string
when it wont ever be null and
string?
when it is nullable in .net 6?
Was this page helpful?