我正在使用vb.net来创建基于Web的应用程序。我尝试创建简洁易用的代码。
我的问题是: 我将创建一个具有属性的类,它只能具有constaint值(可能来自另一个类),我希望设计者提供aceptable值。
I want to see like in the picture
例如: 我应该在下面的代码中更改什么?
Public Class users
private _gender as byte
public writeonly property Gender as byte
set(value as byte)
_gender = value
End set
End property
End Class
Public Class genders
Public ReadOnly Property Female As Byte
Get
Return 0
End Get
End Property
Public ReadOnly Property Male As Byte
Get
Return 1
End Get
End Property
End Class
答案 0 :(得分:0)
使用Enum
Public Enum Genders As Byte
Female = 0
Male = 1
End Enum
如果你需要其他类型,那么或Const
或Shared
类的属性,然后整数
Public Class SomeTypes
Public Const TypeOne As String = "One"
Public Const TypeTwo As String = "Two"
Public Shared ReadOnly Property TypeThree As String = "Three"
End Class