繁体   English   中英

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

[英]Class property should be offered from another class (vb.net)

我正在使用vb.net创建基于Web的应用程序。 我尝试创建干净且易于使用的代码。

我的问题是:我将创建一个具有属性的类,该属性只能具有约束值(也许来自另一个类),并且我希望设计师提供可接受的值。

我想看图片

示例:我应该在下面的代码中更改什么?

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   

使用Enum

Public Enum Genders As Byte
    Female = 0
    Male = 1
End Enum

或类的ConstShared属性(如果需要其他类型,则为Integer)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM