I believe using get; set; like this was implemented in the 3.X framework. In this case you cannot call any custom methods when a property is being changed.

public bool FormEnabled { get; set; }

But if you implement it the second way you can:

private bool _frmEnabled;
    public bool FrmEnabled
      get { return _frmEnabled; }
        _frmEnabled = value; 
    private static void CheckValue(bool Value)
      if (Value == false)
        throw new InvalidProgramException("You cannot set this value to false");

This was added as a matter of convenience so you did not have to encapsulate private fields if you didn't care about when the value changes of a property.

I have beed using CodeDom to generate codes. I was generating property using CodeMemberProperty. Can anybody tell me how to generate property like this:


instead of

This question has already been answered. Start a new discussion instead.