normally you can set a default value for your properties by giving the private property a value.

private string description = "none";
public string Description
        return description;
        description = value;

but the auto implemented properties which were introduced with C# 3.0 the syntax does look like this

public string Description { get; set; }

The only way to give auto implemented properties a default value is to set the value in constructor.


Constructor for Class with auto implemented propertie with default value

this will give you a default value for your auto-implemented property, without breaking object initializer functionallity.

object initialiser not broken

more informations in the MSDN Auto-Implemented Properties

Leave a Reply