Explicitly numbering enum values

When enum raw values have meaning outside your code (or are serialised as with Unity), I find it good practice to explicitly number each value to avoid any dependence on order - eg:
White = 0,
Blue = 1,
etc

2 Likes

I tend to find this a good practice as well.

2 Likes

Yup that’s a good tip, especially if you intend on reordering them in the future. Instead of 1,2,3 I would put 10,20,30 so you can add values in between them if needed.

2 Likes

Privacy & Terms