2 ms·
For me, enums are just a way to eliminate canonical magic strings throughout. They also have the happy side effect of storing as an integer in the database, but
by bob1029 5y ago
For me, enums are just a way to eliminate canonical magic strings throughout. They also have the happy side effect of storing as an integer in the database, but I do sometimes apply a .ToString() in those situations where users will be looking at the data frequently.
There are actually very few cases where I would say enums should not be used. The most obvious one being open-ended types where the list of members will always be growing (e.g. if you made each user of a system a member). You should also not use enums to convey a compounding of logical facts - these get nasty really fast in my experience. Sometimes it is better to just have 5-10 boolean flags on a type than to try and cram every logical combination of those things into canonical enumeration members.
- gjulianm 5y agoYou can use flag enums for the logical facts. Not always, but sometimes they can be useful and make comparisons/checks easier.