I am trying to define an Enum and add valid common separators which used in CSV or similar files. Then I am going to bind it to a ComboBox as a data source so whenever I add or remove from the Enum definition, I would not need to change anything in the combo box.
The problem is how can I define enum with string representation, something like:
public enum SeparatorChars{Comma = ",", Tab = "\t", Space = " "}
You can’t – enum values have to be integral values. You can either use attributes to associate a string value with each enum value, or in this case if every separator is a single character you could just use the
charvalue:(EDIT: Just to clarify, you can’t make
charthe underlying type of the enum, but you can usecharconstants to assign the integral value corresponding to each enum value. The underlying type of the above enum isint.)Then an extension method if you need one: