Use flag enum and combine them - CSharp Custom Type

CSharp examples for Custom Type:Enum

Description

Use flag enum and combine them

Demo Code

using static System.Console;
using System;/*from www  .jav a  2  s  . com*/
class Program
{
   static void Main(string[] args)
   {
      var p2 = new Person
      {
         Name = "Back",
         DateOfBirth = new DateTime(1998, 3, 17)
      };
      WriteLine($"{p2.Name} was born on {p2.DateOfBirth:d MMM yy}");
      p2.BucketList = Level.B | Level.E;
   }
}
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
}

Result


Related Tutorials