Best practice naming convention for const enum, excluding circular definition

This is a kind of duplicate question , but there was no real solution.

So let's go. Let's say I have:

public enum Color { Red, Blue, Green } public class BlueUnicorn { private const Color Color = Color.Blue; } 

But I get a compiler error. This is strange, although not intellisense on this. The constant value estimate for "BlueUnicorn.Color" includes a circular definition.

I feel like I have a crack here. What should be named according to the best practice naming convention?

+4
source share
2 answers

You can name this field as you. To fix a compilation error, simply add the enumeration namespace before Color.Blue .

+4
source

You do not have a crack in the agreement (an excellent term, by the way!). Convention (2) does not apply, as for properties, not fields or constants. So you can call it something like UnicornColor .

As a side note, I appreciate that this is probably not your real code (unless you really are writing a Unicorn simulator!), But it seems to me that having the BlueUnicorn class is wrong. Having a class defined based on a specific constant inside this class seems too specific - is it really that Color will be an attribute of the Unicorn class?

I don’t know if this applies to your real code, but maybe your design is a bit wrong and the question never arises?

+2
source

All Articles