I have a comma delimited file with ” as a text qualifier. Currently I have an enum class that hardcodes in the file columns names. However I need to change it to dynamically grab the file column names and put them into the enum. Any suggestions on how to do this in C#?
Share
An enum is designed to be defined at compile time, and not modified dynamically. While there are ways to do it through reflection, it’s not in the least useful because you can’t write any code that uses the dynamically generated values.
What you probably want is a
Dictionarywhere the key is the column name and the value is the index of that column in the file, aListof column names (so you can find the column name by index), or both (so you can do a lookup in either direction).Dictionaryis the most likely need though, based on your post.