Storing a user input into a string variable in C# [duplicate]

Assuming you have nullable reference types turned on, the warning is correctly pointing out that you are casting null to a non-nullable type - string. It is not about the type of err being non-nullable. err is nullable, as vars always are.

If you cast to string? instead, which is nullable, then the warning goes away:

var err = (string?)null;