In The Hand LtdIn The Hand
GetName Method (enumType, value)
NamespacesInTheHandEnumHelperGetName(Type, Object)
.NET Components for Mobility
Retrieves the name of the constant in the specified enumeration that has the specified value.
Declaration Syntax
C#Visual Basic
public static string GetName(
	Type enumType,
	Object value
)
Public Shared Function GetName ( _
	enumType As Type, _
	value As Object _
) As String
Parameters
enumType (Type)
An enumeration type.
value (Object)
The value of a particular enumerated constant in terms of its underlying type.
Return Value
A string containing the name of the enumerated constant in enumType whose value is value, or null if no such constant is found.
Examples
The following code sample illustrates the use of GetName:
CopyVB.NET
Imports System

    Public Class GetNameTest

        Enum Colors
            Red
            Green
            Blue
            Yellow
        End Enum 'Colors


        Enum Styles
            Plaid
            Striped
            Tartan
            Corduroy
        End Enum 'Styles


    Public Shared Sub Main() 
        MessageBox.Show("The 4th value of the Colors Enum is " + EnumHelper.GetName(GetType(Colors), 3))
        MessageBox.Show("The 4th value of the Styles Enum is " + EnumHelper.GetName(GetType(Styles), 3))
    End Sub 'Main


End Class 'GetNameTest
CopyC#
using System;

public class GetNameTest 
{
    enum Colors { Red, Green, Blue, Yellow };
    enum Styles { Plaid, Striped, Tartan, Corduroy };

    public static void Main() 
    {
        MessageBox.Show("The 4th value of the Colors Enum is " + EnumHelper.GetName(typeof(Colors), 3));
        MessageBox.Show("The 4th value of the Styles Enum is " + EnumHelper.GetName(typeof(Styles), 3));
    }
}
Exceptions
ExceptionCondition
ArgumentException enumType is not an System.Enum. -or- value is neither of type enumType nor does it have the same underlying type as enumType.
See Also

Assembly: InTheHand (Module: InTheHand) Version: 7.0.0.0