简体   繁体   中英

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

I am using vb.net for creating web based applications. I try to create clean and easy to use code.

My problem is: I am going to create a class with a property, which can has constaint values only (maybe from another class) and I want the designer to offer aceptable values.

I want to see like in the picture

example: What should I change in the code below?

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   

Use Enum

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

Or Const or Shared properties of class if you need some other type then 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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