Casting is not directly a bad practice. It is a smell... a sign there might be a potential bad practice somewhere nearby.
In this case, the potential bad practice is comparing an Enum
with an int
at all. That's often (not always) a sign you're doing something else wrong with your design, that the int
value should perhaps also be an Enum
, or you should be using a different mechanism to represent this data.
And, again, it might be just fine.
One example where this is perfectly okay is working with a database, where you need to store an Enum
in a database table as an int
. You'll cast Enum
to int
when saving the data, and cast int
to Enum
when retrieving it. And in these situations a cast is both appropriate and required.