Enum.GetName 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| GetName(Type, Object) |
지정된 값이 있는 지정된 열거형에서 상수의 이름을 검색합니다. |
| GetName<TEnum>(TEnum) |
지정된 값이 있는 지정된 열거형 형식에서 상수의 이름을 검색합니다. |
GetName(Type, Object)
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
지정된 값이 있는 지정된 열거형에서 상수의 이름을 검색합니다.
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
매개 변수
- enumType
- Type
열거형 형식입니다.
- value
- Object
열거된 특정 상수의 기본 형식 값입니다.
반품
값이 있는 열거형 상수 enumType 의 이름을 포함하는 문자열이거나 valuenull 이러한 상수가 없는 경우
- 특성
예외
enumType 또는 value .입니다 null.
.NET 8 이상 버전: enumType 부울 지원 열거형 형식입니다.
예제
다음 예제에서는 .의 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
설명
여러 열거형 멤버의 기본 값 GetName 이 동일한 경우 메서드는 해당 열거형 멤버 중 하나의 이름을 반환합니다. 그러나 항상 동일한 열거형 멤버의 이름을 반환한다고 보장하지는 않습니다. 따라서 여러 열거형 멤버의 값이 같으면 애플리케이션 코드는 특정 멤버의 이름을 반환하는 메서드에 의존해서는 안 됩니다.
적용 대상
GetName<TEnum>(TEnum)
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
- Source:
- Enum.cs
지정된 값이 있는 지정된 열거형 형식에서 상수의 이름을 검색합니다.
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
형식 매개 변수
- TEnum
열거형의 형식입니다.
매개 변수
- value
- TEnum
열거된 특정 상수의 기본 형식 값입니다.
반품
값이 있는 열거형 상수 TEnum 의 이름을 포함하는 문자열이거나 valuenull 이러한 상수가 없는 경우
예외
.NET 8 이상 버전: TEnum 부울 지원 열거형 형식입니다.