Normally, you want to use compiler features of enum types to full potential
public enum NPCType {
Frog = 0,
Dog,
Mouse,
Cat, // you can also keep this comma so that you can reorder them freely in the future
}
This is contrary to what you wanted, but in general, you want to make your enum handling code order-insensitive.
If you depend on the exact values, this is not a smart choice, and you will likely run into trouble in the long run.
The point of an enum value is usually not to represent critical information such as order, but to opaquely enumerate sequential constants and make arbitrary magic indices appear as text.
If you really want to represent critical information, then do what WarmedxMints suggested, but when you really think about it, whatâs the point of doing it in this case? The difference is only an illusion, and youâll only fool yourself later.
public enum NPCType {
Frog = 0,
Dog = 1,
Mouse = 3,
Cat = 2
}
is the exact same thing as
public enum NPCType {
Frog = 0,
Dog,
Cat,
Mouse
}
The only difference (apart from the clutter) is that youâve tricked your eyes into some false sense of order, which has no effect on your code whatsoever.
The way you use enum values as âcriticalâ data is to correlate this ordering with some other mechanism, maybe some kind of priority etc. I.e. if you reorder data in this enum above
public enum NPCType {
Frog = 0, // this is only to make it more readable for your future self
Mouse,
Dog,
Cat
}
Your code shouldnât fall apart, but should instead treat Mouse as somehow more important than Cat IF the order should be relevant at all, and most likely itâs just an ID, the exact value of which shouldnât matter during runtime, as long as 3 always maps to all things Cat, and 2 always maps to all things Dog etc.
So what youâre doing is a code smell.