2015-11-29 22 views
0

我正在使用vb.net創建基於Web的應用程序。我嘗試創建簡潔易用的代碼。類屬性應該從另一個類提供(vb.net)

我的問題是: 我要創建一個類的屬性,可以有(從另一個類也許)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

使用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 
+0

很簡單的解決方案。我使它變得複雜。 謝謝你的快速回答 – tihi

相關問題