Hi,
is there any difference between accessor written as
get
{
}
get;

Yes.

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; }
      set 
      {
        CheckValue(value);
        _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:

get;

instead of

get
{
}

You should probably close this thread and post a new question as the topic has changed.

Thanks, I will do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.