Format Enum value into hexadecimal in CSharp

Description

The following code shows how to format Enum value into hexadecimal.

Example


using System;/*from  ww  w  .java  2  s.c o m*/

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"));

    }
}

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