I have a long list of languages and their respective codes (http://pastebin.com/rn4JbTtP), which was generated by MP4Box.
I want to load this list into some sort of key-value store in C# (like a dictionary), so that the user will be able to select a language from a combo box and the program will return the respective language code.
Is there any way this can be done without reading the text file each time the program is run? If so, how?
UPDATE (as commented here): Sorry, I didn’t explain myself clearly. I’ve got no problem with reading text files, it’s just that the current format requires a lot of parsing before it can be fed into a Dictionary. What will be the best way to store these pairs so that it will require the least amount of parsing at runtime?
You will have to read the file anyway on the startup of your application.
One solution could be to create an xml file containing your languages like this:
and you can also have a small class to hold the name and the code of the language like this:
and a reading method to read all languages:
then you may bind your combo box data source to the language list like this:
Now, if you don’t want to create a file for languages you may create a class which keeps all your languages like this: