What are the performance implications between these two items? I've seen the static class in the wild recently and I'm not sure what to make of it.
public enum SomeEnum
{
One = 1,
Two,
Three
}
public static class SomeClass
{
public static readonly int One = 1;
public static readonly int Two = 2;
public static readonly int Three = 3;
}
Well, for one, type safety, at least, type safety that is not as easily circumvented. For example, using an enumerated value I can create a function prototype such as
void Foo( SomeEnum value );
Whereas with your static class I would have to take an int parameter. Sure, you can cast away the type safety, but it's easier to use and makes it more obvious, and you can also perform conversions more easily. Also, enum's give auto incremented values, pretty-print support in the debugger, binding benefits with controls like a property grid. You get the idea.
Enums are embedded directly in IL whereas fields (like the ones you have in your class) will need a field load instruction which may be slightly more expensive. Here is the IL code for calling a method that accepts an enum versus fields.
The difference is type safety. Suppose you have two of these enums. How are you going to tell the difference:
vs
So everywhere you have an expression which wants to be one of a particular set of values, you can make it clear to both the reader and the compiler which set of values you're interested in if you use enums. With just ints... not so much.