Compare two Enum data type values in CSharp

Description

The following code shows how to compare two Enum data type values.

Example


using System;// ww  w . j  a v  a  2 s .c  o  m

enum EmpType : byte {
    Manager = 10,
    Grunt = 1,
    Contractor = 100,
    VP = 9
}

class Program {
    static void Main(string[] args) {
        EmpType Joe = EmpType.VP;
        EmpType Fran = EmpType.Grunt;

        if (Joe < Fran)
            Console.WriteLine("Joe's value is less than Fran's value.");
        else
            Console.WriteLine("Fran's value is less than Joe's value.");
    }
}

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