类属性应该从另一个类(vb.net)提供

时间:2015-11-29 12:05:07

标签: asp.net vb.net visual-studio

我正在使用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   

1 个答案:

答案 0 :(得分:0)

使用Enum

Public Enum Genders As Byte
    Female = 0
    Male = 1
End Enum
如果你需要其他类型,那么

ConstShared类的属性,然后整数

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