Is it possible to add a string with spaces or special characters to an enum?
For example, I have a string Insurance KR Users (Name), I have tried to include this string into an enum:
public enum MemberGroup
{
Insurance KR Users (Name)
}
but it throws an error.
How can I include these types of strings into enum?
The enum members itself must be a valid identifier, so it can’t contain spaces or special characters.
But you could use the
DescriptionAttributeto provide a more complete description of each enum value:To retrieve the description, use something like this: