Mega Code Archive

 
Categories / C# Tutorial / Data Type
 

Loop through the enum data type

using System;    class MainClass {    enum Week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturaday,Sunday };      public static void Main() {      Week i;       for(i = Week.Monday; i <= Week.Sunday; i++)         Console.WriteLine(i + " has value of " + (int)i);      }  } Monday has value of 0 Tuesday has value of 1 Wednesday has value of 2 Thursday has value of 3 Friday has value of 4 Saturaday has value of 5 Sunday has value of 6