OpenNETCF Smart Device Framework 2.3
Retrieves the name of the constant in the specified enumeration that has the specified value.

Namespace:  OpenNETCF
Assembly:  OpenNETCF (in OpenNETCF.dll) Version: 2.3.0.0

Syntax

C#
public static string GetName(
	Type enumType,
	Object value
)
Visual Basic (Declaration)
Public Shared Function GetName ( _
	enumType As Type, _
	value As Object _
) As String
Visual Basic (Usage)
Dim enumType As Type
Dim value As Object
Dim returnValue As String

returnValue = Enum2.GetName(enumType, _
	value)
Visual C++
public:
static String^ GetName(
	Type^ enumType, 
	Object^ value
)
J#
public static String GetName(
	Type enumType,
	Object value
)
JScript
public static function GetName(
	enumType : Type, 
	value : Object
) : String
JavaScript
OpenNETCF.Enum2.GetName = function(enumType, value);

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

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 (Based on the example provided with desktop .NET Framework):
CopyC#
[Visual Basic] 
            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 " + [OpenNETCF.Enum].GetName(GetType(Colors), 3))
                    MessageBox.Show("The 4th value of the Styles Enum is " + [OpenNETCF.Enum].GetName(GetType(Styles), 3))
                End Sub 'Main

            End Class 'GetNameTest
CopyC#
[C#] 
            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 " + OpenNETCF.Enum.GetName(typeof(Colors), 3));
                    MessageBox.Show("The 4th value of the Styles Enum is " + OpenNETCF.Enum.GetName(typeof(Styles), 3));
                }
            }

Exceptions

ExceptionCondition
System..::.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