c# property setter body without declaring a class-level property variable

前端 未结 8 928
清歌不尽
清歌不尽 2021-01-11 17:38

Do I need to declare a class-level variable to hold a property, or can I just refer to self.{propertyname} in the getter/setter?

In other words, can I d

8条回答
  •  悲&欢浪女
    2021-01-11 18:15

    Check MSDN Properties Overview

    While a property definition generally includes a private data member, this is not required. The get accessor could return a value without accessing a private data member. One example is a property whose get method returns the system time. Properties enable data hiding, the accessor methods hide the implementation of the property.

提交回复
热议问题