I have config values as shown below
add key="Screen1" value ="Admin"
add key="Screen2" value ="Log"
In future new screens will get added. In C#, I need to create an array of string with these screen names. How can we do this (keeping in mind that the code need to work even if we add new screens)?
Note 1: I am looking for an approach that does not use custom configuration.
Note 2: I will have maximum of 10 config items with the name starting as “Screen”. But I will have 10,000 other config items.
REFERENCE
If you have a lot of settings (say, 10K, like you specified in the comments), you may benefit from the fact that the AppSettings collection is optimized for lookup by key. For this, you’ll have to repeatedly try “Screen1”, “Screen2”, “Screen3”, etc., and stop when no value is found:
This approach, however, is exactly the kind of “premature optimization” that Mr. Knuth warned us about. The config file simply shouldn’t contain that many settings, period.
Another disadvantage: keep in mind that this approach assumes that there are no gaps in the numbering of “Screen*” settings. That is, if you have “Screen1”, “Screen2”, and “Screen4”, it will not pickup the last one. If you’re planning on having a lot of these settings, it will become very inconvenient to “shift” all the numbers every time you add or remove a setting.