爲對象定義屬性而不是直接訪問私有變量有什麼好處?公共屬性定義
相反的:
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- vs-automatic-properties,http://stackoverflow.com/questions/111461/auto-implemented-getters-and-setters-vs-public-fields,http://stackoverflow.com/questions/1277572/should-i- use-public-properties-and-private-fields-or-public-fields-for-data,http://stackoverflow.com/questions/3069901/properties-vs-fields-need-help-grasping-the-uses-屬性超越領域等等。 – 2010-07-08 13:32:19
:)是啊我也發現它重複...無論如何thnx指向它 – KoolKabin 2010-07-08 18:49:27