When you use an auto property like this, the default value for a property type is a value unless you initialize it elsewhere, for example, in a constructor:
public class Person
{
public string Name { get; set; }
public Person()
{
Name = string.Empty;
}
}
, ( ), - , null, .
, .
auto :
public class Person
{
public string Name { get; private set; }
public Person()
{
Name = string.Empty;
}
}
- . , ?? (null-coalescing) :
public class Person
{
public string Name
{
get { return mName; }
set { mName = value ?? string.empty; }
}
public Person()
{
Name = string.Empty;
}
private string mName;
}