Search code examples
.netc#-3.0propertiesautomatic-properties

How to customize Auto Properties in C# 3.0


Before C# 3.0 we done like this:

class SampleClass
{
   private int field;
   public int Property { get { return this.field } set { this.field = value } }
}

Now we do this:

class SampleClass
{
   public int Property { get; set; }
}

(Look ma! no fields!) Now if I want to customize the Getter or the Setter, the field must be explicit as it was in C#2.0?


Solution

  • Yes, that's the only way. No shortcut for customization (other than access modifiers).