namespace Foo
{
public enum MyEnum
{
High, Low
}
public class Class1
{
public MyEnum MyProperty { get; set; }
}
}
MyEnum
is declared outside Class1
cause I need it here and in other classes
Seems good, but what if I decide later to delete the file containingClass1
?
MyEnum
declaration will be lost!!
What's the best practice to code shared enums between classes?
The best practice is creating separate file for each class, enum, or other type.
MyEnum.cs
namespace Foo
{
public enum MyEnum
{
High,
Low
}
}
Class1.cs
namespace Foo
{
public class Class1
{
public MyEnum MyProperty { get; set; }
}
}
What's the best practice to code shared enums between classes?
Have your enumerations each in a file of its own, with the same name as the enumeration.
// Foo\MyEnum.cs
namespace Foo
{
public enum MyEnum
{
High, Low
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With