I have a (read only) table containing some config info, for example:
Red - 1,
Green - 2,
Orange - 3.
What is the easiest way to load this into some collection, so that I can write, for example:
byte x = MyColl.Red;
One option would be to use an enum
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
The problem with this is that it needs to be hard coded at compile time, so reading it from a table will not make sense.
The other option would be tio use Dictionary Class
Represents a collection of keys and values.
where you could look at
Dictionary<string, byte>
So as to use it such that
byte x = MyCollDictionary["Red"];
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.