Enum.GetName メソッドとは? わかりやすく解説

Enum.GetName メソッド

指定した値を持つ指定した列挙体にある定数の名前を取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Shared Function GetName
 ( _
    enumType As Type, _
    value As Object _
) As String
[ComVisibleAttribute(true)] 
public static string GetName
 (
    Type enumType,
    Object value
)
[ComVisibleAttribute(true)] 
public:
static String^ GetName (
    Type^ enumType, 
    Object^ value
)
/** @attribute ComVisibleAttribute(true) */ 
public static String GetName (
    Type enumType, 
    Object value
)
ComVisibleAttribute(true) 
public static function GetName
 (
    enumType : Type, 
    value : Object
) : String

パラメータ

enumType

列挙型

value

基になる型に関連して列挙される特定の定数の値。

戻り値
値が value である enumType 内にある列挙型定数の名前が含まれ文字列そのような定数が見つからない場合は、null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

enumType または valuenull 参照 (Visual Basic では Nothing) です。

ArgumentException

enumTypeEnum ではありません。

または

value の型が enumType ではなく、基になる型も enumType と同じではありません。

使用例使用例

GetName使用方法については、次のコード例参照してください

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()
 
        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 'Main
End Class 'GetNameTest
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));
    }
}
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 ) );
}
import System.*;

public class GetNameTest
{
    enum Colors
    {
        red (0),
        green (1),
        blue (2),
        yellow (3);
    }//Colors

    enum Styles
    {
        plaid (0),
        striped (1),
        tartan (2),
        corduroy (3);
    }//Styles

    public static void main(String[]
 args)
    {
        Console.WriteLine("The 4th value of the Colors Enum is {0}", 
            Enum.GetName(Colors.class.ToType(), (Int32)3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", 
            Enum.GetName(Styles.class.ToType(), (Int32)3));
    } //main
} //GetNameTest
import System;

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

    public static function
 Main() {

        Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(Colors,
 3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(Styles,
 3));
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Enum.GetName メソッド」の関連用語

Enum.GetName メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Enum.GetName メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS