如何在不涉及逻辑的情况下,用VB.NET实现属性的获取与设置?
- 内容介绍
- 文章标签
- 相关推荐
本文共计237个文字,预计阅读时间需要1分钟。
我在网上看到的很多文章都说,在VB.NET中创建属性时,应该在类中使用get / set方法和private / protected成员变量。例如:
Public Class Person Private _name As String Public Property Name As String Get Return _name End Get Set(value As String) _name=value End Set End PropertyEnd Class
我在网上看到的许多文章都说,在vb.net中创建属性时,他们应该在类中使用get / set方法和private / protected成员变量.像这样:
Public Class Person Private _name as string public property Name as string get return _name end get set(byval value as string) _name = value end set end property end class
如果属性的get / set中没有逻辑,为什么不会像这样编写相同的属性:
Public class Person Public Property Name as string end class
这是因为属性只是从外部进入类的访问者,你会将变量存储在类中吗?
原因是这些指南和教程是在VB.NET 4.0发布之前发布的.没有其他理由不使用自动实现的属性.本文共计237个文字,预计阅读时间需要1分钟。
我在网上看到的很多文章都说,在VB.NET中创建属性时,应该在类中使用get / set方法和private / protected成员变量。例如:
Public Class Person Private _name As String Public Property Name As String Get Return _name End Get Set(value As String) _name=value End Set End PropertyEnd Class
我在网上看到的许多文章都说,在vb.net中创建属性时,他们应该在类中使用get / set方法和private / protected成员变量.像这样:
Public Class Person Private _name as string public property Name as string get return _name end get set(byval value as string) _name = value end set end property end class
如果属性的get / set中没有逻辑,为什么不会像这样编写相同的属性:
Public class Person Public Property Name as string end class
这是因为属性只是从外部进入类的访问者,你会将变量存储在类中吗?
原因是这些指南和教程是在VB.NET 4.0发布之前发布的.没有其他理由不使用自动实现的属性.
