I got a need for two extacly idential enums with diffrent names
I can do
enum DoorStatus{Open,Closed,Locked,Broken};
enum WindowStatus{Open,Closed,Locked,Broken};
and will probably be bit easier to read.
but Id rather not to duplicate code
in C++ id do
typedef Door,Window;
what is the soultion in C#?
and why have both you ask?
I got Application That Handles a Window
application that handles a Door
.
I want the Window
application devoloper send me data using 'WindowStatus' enum
the 'Door' guy use 'DoorStatus' enum.
I believe that user should know or care I got other devices that can be abstracted similarly.
EDIT: used
enum HatchStatus{Open,Closed,Locked,Broken};
using DoorStatus = HatchStatus;
using WndowStatus = HatchStatus;
EDIT2:
Error A using clause must precede all other elements defined in the namespace except extern alias declarations
:(
6. Attaching Multiple Values. The Enum constructor can accept multiple values. Similarly, we can add any values we want to the enum, such as the proper case symbols, “He”, “Li” and “Be”, for example.
Enums type can be an integer (float, int, byte, double etc.) but if you use beside int, it has to be cast. Enum is used to create numeric constants in . NET framework.
Definition. An Enumeration (or enum ) is a data type that includes a set of named values called elements or members. The enumerator names are usually identifiers that behave as constants in the language.
You can also create an alias for a namespace or a type with a using alias directive.
If you just want an alias, you can use a using
directive:
using Enum2 = Enum1;
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