Enum.GetName Yöntem

Tanım

Aşırı Yüklemeler

Name Description
GetName(Type, Object)

Belirtilen sabit listesi içinde belirtilen değere sahip 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)

Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
Enum.cs

Belirtilen sabit listesi içinde belirtilen değere sahip 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

Numaralandırma türü.

value
Object

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

Döndürülenler

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

Öznitelikler

Özel durumlar

enumType veya value şeklindedir null.

enumType bir Enumdeğildir.

-veya-

value türünde enumType değildir veya ile aynı temel türe 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 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 sabit listesi ü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)

Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
Enum.cs
Kaynak:
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 türü açısından değeri.

Döndürülenler

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

Özel durumlar

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

Şunlara uygulanır