Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Demonstration of enumeration types in C#.Lecture 2 - slide 8 : 43
Program 1
using System;

class NonSimpleTypeDemo{

  public enum Ranking {Bad, OK, Good}

  public enum OnOff: byte{
    On = 1, Off = 0}

  public static void Main(){
    OnOff status = OnOff.On;
    Console.WriteLine();
    Console.WriteLine("Status is {0}", status);                  

    Ranking r = Ranking.OK;
    Console.WriteLine("Ranking is {0}", r  );                      
    Console.WriteLine("Ranking is {0}", r+1);                    
    Console.WriteLine("Ranking is {0}", r+2);                    
 
    bool res1 = Enum.IsDefined(typeof(Ranking), 3);
    Console.WriteLine("{0} defined: {1}", 3, res1);              

    bool res2= Enum.IsDefined(typeof(Ranking), Ranking.Good);    
    Console.WriteLine("{0} defined: {1}", Ranking.Good , res2);  

    bool res3= Enum.IsDefined(typeof(Ranking), 2);    
    Console.WriteLine("{0} defined: {1}", 2 , res3);             

    foreach(string s in Enum.GetNames(typeof(Ranking)))          
       Console.WriteLine(s);
  }

}
 
 
 
 
 
 
 
 
 
 
 
 
Output: Status is On
 
 
Output: Ranking is OK
Output: Ranking is Good
Output: Ranking is 3
 
 
Output: 3 defined: False
 
 
Good defined: True
 
 
2 defined: True
 
"Bad" "OK" "Good"