Difference between two class definitions in c#

128 views Asked by At

Failing finding an answer I can understand, could someone explain the difference between the following:

// One
private Guid mCategoryID;
public Guid CategoryID
{
    get
    {
        return mCategoryID;
    }
    set
    {
        mCategoryID = value;
    }
}
    
// Two
public Guid CategoryID {get; set;}

Is the get/set code in the section above: One doing the same as Two or do they work differently?

Jerry

1

There are 1 answers

0
Bikalpkarn On

Yes, Both one and two are same .

  • A property which contains a both get and set accessors, then we will call it as read-write property.
  • get accessor, then we will call it as a read-only property. -set accessor, then we will call it as write-only property.