Fla*_*ash 4 vb.net oop design-patterns properties
在VB.NET中,使用Property关键字的优点是什么,而不是:
Private MyProperty as String
Public Sub setP(ByVal s as String)
MyProperty = s
End Function
Public Function getP() as String
return MyProperty
End Function
Run Code Online (Sandbox Code Playgroud)
来自Java我倾向于使用这种风格而不是Property...End Property- 有什么理由不这样做吗?
Han*_*ant 10
您正在完成编译器所做的工作.Property关键字的优点:
VS2010中使用auto属性语法的相同声明:
Public Property P As String
Run Code Online (Sandbox Code Playgroud)
编译器自动生成getter和setter方法以及私有支持字段.必要时,您可以重构访问器.