I will answer, not because I think the other answers are bad, but because I think there is another thing to be said in this case.
We have two questions in one:
- About best practice for you Enum
- About refactoring an Enum
1)Is this a Best Practice with Enum in C#?
Well, in your case, since you Enum seems to be kind of hierarchic, I would define them as flags, and benefit from that when using and comparing the values.
[Flags]
enum Designation
{
None = 0x0,
TeamLead = 0x1,
Manager = 0x2,
Associate = 0x4
}
Then you could use a code like this:
string CheckAboveManager(Designation designation)
{
if (designation >= Designation.Manager)
return "It's a manager or higher";
return "Is lower than manager";
}
The other option of using a object-oriented structure will work only if there is specific behavior or structure you want to separate concerns with. If it is a case of just defining a property (that why there are enums!), them I see no need to create inheritance, but if it is the case, use the accepted answer.
2) Now if we decide to change the enum element from "TeamLead" to
"Lead" then we have to modify the above line of code as well i.e.
designation == Designation.TeamLead to designation == Designation.Lead
Well, it was already well explained that refactoring is not an issue if you are using VS IDE, you can even use other tools like DevExpress CodeRush! or ReSharper to get an even better (and very safe) result from refactoring.
0
asNone
enum
so you CAN rename them. VS renaming tools work just fine onenum
.0
,1
, and2
(which are the default values anyway)? Are you going to write code that depends onAssociate
having the value 2? What would you lose by writingenum Designation { Manager, TeamLead, Associate }
?designation.ToString()
somewhere in your UI. This is absolutely bad practice.