Thursday 4 June 2009

New property syntax in C#3.0

Prior to C#3.0 we would use the following syntax for creating properties:

private string _GetAndSet;
public string GetAndSet { get { return _GetAndSet; } set { _GetAndSet = value; } }


private string _SetOnly;
public string SetOnly{ get { return _SetOnly; } set { _SetOnly = value; } }


C#3.0 allows us to use the following syntax which is the equivalent of above.

public string GetAndSet { get; set; }

public string SetOnly{ get; private set; }

No comments:

Free Hit Counter