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_Notes { get; set; }
//Create instance of foo
foo myFoo = new foo();
//Get value of Address_Notes
var notesValue = myFoo.Address_Notes; //Returns null
Am I crazy to think that a non-nullable string’s value should default to String.Empty? Is there a standard way of forcing this behavior, other than a custom getter?
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.Emptyin the constructor for your class (foo).