Enum.GetName Yöntem

Tanım

Aşırı Yüklemeler

GetName(Type, Object)

Belirtilen değere sahip belirtilen numaralandırmadaki sabitin adını alır.

GetName<TEnum>(TEnum)

Belirtilen değere sahip belirtilen numaralandırma türündeki sabitin adını alır.

GetName(Type, Object)

Source:
Enum.cs
Source:
Enum.cs
Source:
Enum.cs

Belirtilen değere sahip belirtilen numaralandırmadaki sabitin adını alır.

public:
 static System::String ^ GetName(Type ^ enumType, System::Object ^ value);
public static string GetName (Type enumType, object value);
public static string? GetName (Type enumType, object value);
[System.Runtime.InteropServices.ComVisible(true)]
public static string GetName (Type enumType, object value);
static member GetName : Type * obj -> string
[<System.Runtime.InteropServices.ComVisible(true)>]
static member GetName : Type * obj -> string
Public Shared Function GetName (enumType As Type, value As Object) As String

Parametreler

enumType
Type

Bir numaralandırma türü.

value
Object

Belirli bir numaralandırılmış sabitin, temel alınan türü açısından değeri.

Döndürülenler

içinde değeri valuenull olan veya böyle bir sabit bulunamazsa numaralandırılmış sabitin enumType adını içeren bir dize.

Öznitelikler

Özel durumlar

enumType veya value şeklindedir null.

enumType bir Enumdeğildir.

-veya-

value türünde enumType değildir ve ile aynı temel türüne enumTypesahip değildir.

.NET 8 ve sonraki sürümleri: enumType Boole destekli bir numaralandırma türüdür.

Örnekler

Aşağıdaki örnekte kullanımı gösterilmektedir GetName.

using namespace System;

enum class Colors
{
   Red, Green, Blue, Yellow
};

enum class Styles
{
   Plaid, Striped, Tartan, Corduroy
};

int main()
{
   Console::WriteLine(  "The 4th value of the Colors Enum is {0}", Enum::GetName( Colors::typeid, 3 ) );
   Console::WriteLine(  "The 4th value of the Styles Enum is {0}", Enum::GetName( Styles::typeid, 3 ) );
}
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy
using System;

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

    public static void Main() {

        Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
    }
}
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy
open System

type Colors =
    | Red = 0
    | Green = 1
    | Blue = 2
    | Yellow = 3

type Styles =
    | Plaid = 0
    | Striped = 1
    | Tartan = 2
    | Corduroy = 3

printfn $"The 4th value of the Colors Enum is {Enum.GetName(typeof<Colors>, 3)}"
printfn $"The 4th value of the Styles Enum is {Enum.GetName(typeof<Styles>, 3)}"
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy
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() 
        Console.WriteLine("The 4th value of the Colors Enum is {0}", [Enum].GetName(GetType(Colors), 3))
        Console.WriteLine("The 4th value of the Styles Enum is {0}", [Enum].GetName(GetType(Styles), 3))
    End Sub
End Class
' The example displays the following output:
'       The 4th value of the Colors Enum is Yellow
'       The 4th value of the Styles Enum is Corduroy

Açıklamalar

Birden çok numaralandırma üyesi aynı temel değere sahipse yöntemi, GetName bu numaralandırma üyelerinden birinin adını döndürmesini garanti eder. Ancak, her zaman aynı numaralandırma üyesinin adını döndüreceğini garanti etmez. Sonuç olarak, birden çok numaralandırma üyesi aynı değere sahip olduğunda, uygulama kodunuz hiçbir zaman belirli bir üyenin adını döndüren yönteme bağımlı olmamalıdır.

Şunlara uygulanır

GetName<TEnum>(TEnum)

Source:
Enum.cs
Source:
Enum.cs
Source:
Enum.cs

Belirtilen değere sahip belirtilen numaralandırma türündeki sabitin adını alır.

public:
generic <typename TEnum>
 where TEnum : value class static System::String ^ GetName(TEnum value);
public static string? GetName<TEnum> (TEnum value) where TEnum : struct;
static member GetName : 'Enum -> string (requires 'Enum : struct)
Public Shared Function GetName(Of TEnum As Structure) (value As TEnum) As String

Tür Parametreleri

TEnum

Numaralandırmanın türü.

Parametreler

value
TEnum

Belirli bir numaralandırılmış sabitin, temel alınan türü açısından değeri.

Döndürülenler

içinde değeri valuenull olan veya böyle bir sabit bulunamazsa numaralandırılmış sabitin TEnum adını içeren bir dize.

Özel durumlar

.NET 8 ve sonraki sürümleri: TEnum Boole destekli bir numaralandırma türüdür.

Şunlara uygulanır