Compare two enum value and return the sequence in CSharp

Description

The following code shows how to compare two enum value and return the sequence.

Example


//from w  ww  . j av  a 2 s .  com

using System;
enum Direction { East = 0, West = 2, North = 4, South = 5 };
public class CompareToTest {
    public static void Main() {
        Direction myVeh = Direction.West;
        Direction yourVeh = Direction.East;
        Direction otherVeh = Direction.North;

        Console.WriteLine( myVeh.CompareTo(yourVeh) > 0 ? "Yes" : "No");
        Console.WriteLine( myVeh.CompareTo(otherVeh) > 0 ? "Yes" : "No" );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var