Enum constants can only be of ordinal types ( int by default), so you cannot have string constants in enumerations.
When I want something like "string-based renaming," I create a class to hold constants, just like you, except that I make it a static class to prevent both undesired creation and undesired subclass.
But if you don't want to use a string as a type in method signatures, and you prefer a safer, more restrictive type (like Operation ), you can use a safe enumeration pattern:
public sealed class Operation { public static readonly Operation Name1 = new Operation("Name1"); public static readonly Operation Name2 = new Operation("Name2"); private Operation(string value) { Value = value; } public string Value { get; private set; } }
R. Martinho Fernandes Dec 05 '09 at 8:50 2009-12-05 08:50
source share