In the following contrived C# code, I don’t like that an enum name is the same as the property name.
public enum CollarType
{
Classic,
VNeck
}
public class Shirt
{
public CollarType CollarType { get ... }
}
In the old days when more people were using hungarian / other bizarre naming like class CShirt, this kind of conflict didn’t happen. But today I run into it constantly.
How do you handle this situation? Do you just live with the fact that so many things have the same name, or do you have a better naming scheme?
The only limitation of having the enum name be the same as the property name is that you cannot define the enum as nested type of the class with the property.
E.g. this does not work:
However, on the positive side, it does make the code more readable IMHO because it clearly< shows the association between the enum value and the property: