开发者

How do I define a list of properties

开发者 https://www.devze.com 2023-02-11 01:48 出处:网络
I hav开发者_StackOverflow中文版e a class called \"heater\".One of the properties is \"designstatus\", a string.I want to limit the property to one of three choices; \"current\", \"obsolete\", \"notdes

I hav开发者_StackOverflow中文版e a class called "heater". One of the properties is "designstatus", a string. I want to limit the property to one of three choices; "current", "obsolete", "notdesigned". How would I do this?


You can use an Enum. E.g.:

Public Enum DesignStatus
    Current
    Obsolete
    NotDesigned
End Enum


You can do this using an Enum, but as an Enum is an Integer this isn't going to completely do what you want, so I would suggest doing something similar to this:

Public Enum DesignStatuses
   Current
   Obsolete
   NotDesigned
End Enum

So when you need to get the actual String name of the Enum that you have used you can do:

DesignStatus.ToString("G")

Which will return the actual name of the constant instead of the value.

0

精彩评论

暂无评论...
验证码 换一张
取 消