C# Type GetEnumName

Description

Type GetEnumName returns the name of the constant that has the specified value, for the current enumeration type.

Syntax

Type.GetEnumName has the following syntax.


public virtual string GetEnumName(
  Object value
)

Parameters

Type.GetEnumName has the following parameters.

  • value - The value whose name is to be retrieved.

Returns

Type.GetEnumName method returns The name of the member of the current enumeration type that has the specified value, or null if no such constant is found.

Example


/*from ww w  . j  a v  a  2 s  .  c om*/

using System;

enum ABC { A, B, C }
public class MainClass
{
    public static void Main(String[] argv)
    {
        ABC a = ABC.A;
        System.Console.WriteLine(a.GetType().GetEnumName(a));
    }
}

    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version