adsense

Wednesday, March 31, 2010

Iterate through Enum values

Here is the enum definition

public Enum Employee
{
  Manager=1,
  Lecturer=2,
  AdminOfficer=3
}

Here is the iteration of Enum
foreach ( int val in Enum.GetValues(typeof( Employee)) )
{
  strin text=Enum.GetName( typeof(Employee),val); // gets Manager,Lecturer....etc
   Console.WriteLine(text + " value" + val.ToString()); //val is the actual value in Enum 1.2....etc
}

No comments:

Post a Comment