Get underlying type

   
   
using System;

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

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

        Console.WriteLine(Enum.GetUnderlyingType(typeof(EmpType)));

    }
}

   
    
     


Enum.Format()

   
   

using System;

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

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

        Console.WriteLine("You are a {0}", fred.ToString());
        Console.WriteLine("Hex value is {0}", Enum.Format(typeof(EmpType), fred, "x"));
        Console.WriteLine("Int value is {0}", Enum.Format(typeof(EmpType), fred, "D"));

    }
}

   
    
     


Get Enum's type, hex and value.

   
   
using System;

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

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

        Console.WriteLine("You are a {0}", fred.ToString());
        Console.WriteLine("Hex value is {0}", Enum.Format(typeof(EmpType), fred, "x"));
        Console.WriteLine("Int value is {0}", Enum.Format(typeof(EmpType), fred, "D"));

    }
}

   
    
     


Enum Parse

   
   

using System;

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

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

        EmpType sally = (EmpType)Enum.Parse(typeof(EmpType), "Manager");
        Console.WriteLine("Sally is a {0}", sally.ToString());
    }
}

   
    
     


Get all stats for EmpType.

   
   
using System;

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

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

        Array obj = Enum.GetValues(typeof(EmpType));
        Console.WriteLine("This enum has {0} members:", obj.Length);
    }
}

   
    
     


Enum.IsDefined()

   
   
using System;

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

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

        // Does EmpType have a SaleEmployee value?
        if (Enum.IsDefined(typeof(EmpType), "SalesEmployee"))
            Console.WriteLine("Yep, we have sales people.");
        else
            Console.WriteLine("No, we have no profits....");
    }
}

   
    
     


Enum data type comparison

using System;

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."); } } [/csharp]