CSharp examples for Custom Type:Enum
Cast integer value to enum value
using static System.Console; using System;/*from ww w. j a v a 2 s . c o m*/ class Program { static void Main(string[] args) { var p2 = new Person { Name = "Back", DateOfBirth = new DateTime(2020, 3, 17) }; WriteLine($"{p2.Name} was born on {p2.DateOfBirth:d MMM yy}"); p2.BucketList = (Level)18; WriteLine($"{p2.Name}'s bucket list is {p2.BucketList}"); } } public class Person : object { // fields public string Name; public DateTime DateOfBirth; public Level MyLevel; public Level BucketList; } [System.Flags] public enum Level : byte { None = 0, A = 1, B = 1 << 1, // i.e. 2 C = 1 << 2, // i.e. 4 D = 1 << 3, // i.e. 8 E = 1 << 4, // i.e. 16 F = 1 << 5, // i.e. 32 G = 1 << 6, // i.e. 64 }