bitwise enums in CSharp

Add the System.FlagsAttribute attribute[1]

[Flags]
public enum ItemType
{
	ThirdParty = 0b_0000_0001,
	Buyer = 0b_0000_0010,
	Seller = 0b_0000_0100
}

ItemType both = ItemType.Buyer | ItemType.Seller;
Console.WriteLine((ItemType.ThirdParty & both) == ItemType.ThirdParty); // false
Console.WriteLine((ItemType.Buyer & both) == ItemType.Buyer); // true
Console.WriteLine((ItemType.Seller & both) == ItemType.Seller); // true

  1. Enumeration types - C# reference | Microsoft Learn ↩︎