The source code to demonstrate the HasFlag() method of Enum class is given below. The given program is compiled and executed successfully.
using System;
class Sample
{
enum Directions { EAST=0,WEST=1,NORTH=2,SOUTH=3};
//Entry point of Program
static public void Main()
{
Directions[] direction = { Directions.WEST,Directions.SOUTH,Directions.EAST };
//EAST 0 00
//WEST 1 01
//NORTH 2 10
//SOUTH 3 11
foreach (Directions dir in direction)
{
Console.WriteLine("High bits:");
if (dir.HasFlag(Directions.WEST))
Console.WriteLine("\tWEST");
if (dir.HasFlag(Directions.EAST))
Console.WriteLine("\tEAST");
}
}
}
Output:
High bits:
WEST
EAST
High bits:
WEST
EAST
High bits:
EAST
Press any key to continue . . .
Program:
The source code to demonstrate the HasFlag() method of Enum class is given below. The given program is compiled and executed successfully.
Output: