C
C#2y 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?
2 Replies
Angius
Angius2y ago
Just... use string? Since .NET 6, reference types are non-nullable by default So their nullability needs to be explicitly denoted by that ?
Puck
Puck2y ago
Okay thanks