개인 변수에 직접 액세스하지 않고 개체의 속성을 정의하면 어떤 이점이 있습니까? 대신Public 속성 정의
:
public class A
private _x as integer = 0
Public property X() as integer
Get
return _x
End Get
Set(ByVal value As integer)
_x = value
End Set
End Property
end class
우리는 다음을 수행 할 수없는 이유 :
public class A
public _x as integer = 0
end class
이점은 무엇입니까
?
가능한 중복 항목 : http://stackoverflow.com/questions/1272521/propertywith-no-extra-processing-vs-public-field, http://stackoverflow.com/questions/1180860/c-public-fields- 대 자동 속성, http://stackoverflow.com/questions/111461/auto-implemented-getters-and-setters-vs-public-fields, http://stackoverflow.com/questions/1277572/should-i- public-properties-and-private-fields-or-public-fields-for-data, http://stackoverflow.com/questions/3069901/properties-vs-fields-need-help-grasping-the-uses- of-properties-over-fields 및 더 많은 것. –
:) 그래, 나는 또한 중복을 발견했다 ... 어쨌든 그것을 가리키는 thnx – KoolKabin