What to use besides enum for c#

后端 未结 3 1924
猫巷女王i
猫巷女王i 2021-02-06 00:04

So currently have an enumeration used on the status of an application. However, something feels off when using it against the ui. To many conversions between integer and string

3条回答
  •  渐次进展
    2021-02-06 00:21

    An Enum like construct is definitely the right choice. If for some reason you don't want to use the familiar built in way, you can make you're own with a bir more functionaliy. here's the basic idea:

    class Country {
        private static Country US;
        private static Country JP
    
        static Country() { //initialize static variables }
        private Country( string name ) { //initialize variables of Country instance }
    
        }
    

    There's a design pattern for this, but I forget the name.

提交回复
热议问题