Another option is to use the enumeration class created by Jimmy Bogard .
In essence, you must create a class that inherits its Enumeration . Example:
public class EmployeeType : Enumeration { public static readonly EmployeeType Manager = new EmployeeType(0, "Manager"); public static readonly EmployeeType Servant = new EmployeeType(1, "Servant"); public static readonly EmployeeType Assistant = new EmployeeType(2, "Assistant to the Regional Manager"); private EmployeeType() { } private EmployeeType(int value, string displayName) : base(value, displayName) { }
Then you can use it as an enum with the ability to put methods into it (among other things):
EmployeeType.Manager.ToString(); //0 - Manager EmployeeType.Servant.ToString(); //1 - Servant EmployeeType.Assistant.ToString(); //2 - Assistant to the Regional Manager
You can download it from NuGet .
Although this implementation is not native to the language, the syntax (construction and use) is pretty close to languages ββthat implement enumerations initially better than C # (e.g. Kotlin ).
fabriciorissetto Aug 16 '16 at 22:51 2016-08-16 22:51
source share