properties in C#

前端 未结 4 1350
慢半拍i
慢半拍i 2020-12-31 05:00

Why are we able to write

public int RetInt
{
   get;set;
}

instead of

public int RetInt
{
   get{return someInt;}set{someI         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 05:12

    These are auto implemented properties. Please see http://msdn.microsoft.com/en-us/library/bb384054.aspx for more info.

    Basic reason why these were introduced was to reduce the overhead of programmer of creating a private variable like someInt which had little use than being used in a property.

提交回复
热议问题