Non-Nullable String Initializes as Null

前端 未结 4 905
醉话见心
醉话见心 2021-01-18 02:20

I trying to understand why a non-nullable string initializes to null instead of an empty string. For example:

//Property of class foo
public string Address_N         


        
4条回答
  •  [愿得一人]
    2021-01-18 03:13

    There is no such thing as a "non-nullable string".

    String is a reference type, so its default value is indeed a null.

    You could get around the issue by setting the value to String.Empty in the constructor for your class (foo).

提交回复
热议问题