Comparing Enumeration Values with CompareTo() : enums Definition « Data Type « C# / CSharp Tutorial






using System;
   
public class MainClass
{
    public enum Color
    {
        Red = 0,
        Orange,
        Yellow,
        Green,
        Blue,
        Indigo,
        Violet
    }
   
    static void Main()
    {
        Color MyColor;
   
        MyColor = Color.Green;
        Console.WriteLine("{0}", MyColor.CompareTo(Color.Red)); 
        Console.WriteLine("{0}", MyColor.CompareTo(Color.Green)); 
        Console.WriteLine("{0}", MyColor.CompareTo(Color.Violet)); 
    }
}








2.40.enums Definition
2.40.1.Define Enums
2.40.2.Using the LegalDoorStates Enumeration
2.40.3.Comparing Enumeration Values with CompareTo()
2.40.4.Retrieving an Enumeration Name with GetName()