Enum.GetName Method (Type, Object)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Retrieves the name of the constant in the specified enumeration that has the specified value.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

[<ComVisibleAttribute(true)>]
static member GetName : 
        enumType:Type *
        value:Object -> string

Parameters

enumType
Type: System.Type

An enumeration type.

value
Type: System.Object

The value of a particular enumerated constant in terms of its underlying type.

Return Value

Type: System.String

A string containing the name of the enumerated constant in enumType whose value is value; or null if no such constant is found.

Exception Condition
ArgumentNullException

enumType or value is null.

ArgumentException

enumType is not an Enum.

-or-

value is neither of type enumType nor does it have the same underlying type as enumType.

If multiple enumeration members have the same underlying value, the GetName method guarantees that it will return the name of one of those enumeration members. However, it does not guarantee that it will always return the name of the same enumeration member. As a result, when multiple enumeration members have the same value, your application code should never depend on the method returning a particular member's name.

The following example illustrates the use of GetName.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: