簡體   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