Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.
You seem to misunderstand the above statement. It says that define the enum in namespace level not inside the scope of another type.
Do this:
namespace myNamespace
{
enum foo {A, B, C, D} //Note enum is outside the class
class Myclass
{
magicHappens();
}
}
Don't do this:
namespace myNamespace
{
class Myclass
{
magicHappens();
enum foo //Note enum is inside the class
{
A,
B,
C,
D
}
}
}
and Ideally you should have seperate ".cs" files for your enums in this case "foo.cs".