[DefaultValue]
is only used by (for example) serialization APIs (like XmlSerializer
), and some UI elements (like PropertyGrid
). It doesn't set the value itself; you must use a constructor for that:
public MyType()
{
RetrieveAllInfo = true;
}
or set the field manually, i.e. not using an automatically implemented-property:
private bool retrieveAllInfo = true;
[DefaultValue(true)]
public bool RetrieveAllInfo {
get {return retrieveAllInfo; }
set {retrieveAllInfo = value; }
}
Or, with more recent C# versions (C# 6 or above):
[DefaultValue(true)]
public bool RetrieveAllInfo { get; set; } = true;
public bool RetrieveAllInfo { get; set; } = true;
It's C# 6 feature. – marbel82