Enum.Parse メソッド
文字列形式での 1 つ以上の列挙定数の名前または数値を、等価の列挙オブジェクトに変換します。
オーバーロードの一覧
文字列形式での 1 つ以上の列挙定数の名前または数値を、等価の列挙オブジェクトに変換します。
[Visual Basic] Overloads Public Shared Function Parse(Type, String) As Object
[JScript] public static function Parse(Type, String) : Object;
文字列形式での 1 つ以上の列挙定数の名前または数値を、等価の列挙オブジェクトに変換します。演算で大文字と小文字を区別するかどうかをパラメータで指定します。
[Visual Basic] Overloads Public Shared Function Parse(Type, String, Boolean) As Object
[JScript] public static function Parse(Type, String, Boolean) : Object;
使用例
Parse を使用して、パラメータとして Type と String を受け取る方法については、次のコード例を参照してください。
Imports System
Public Class ParseTest
<FlagsAttribute()> _
Enum Colors
Red = 1
Green = 2
Blue = 4
Yellow = 8
End Enum 'Colors
Public Shared Sub Main()
Console.WriteLine("The entries of the Colors Enum are:")
Dim s As String
For Each s In [Enum].GetNames(GetType(Colors))
Console.WriteLine(s)
Next s
Console.WriteLine()
Dim myOrange As Colors = CType([Enum].Parse(GetType(Colors), "Red, Yellow"), Colors)
Console.WriteLine("The myOrange value has the combined entries of {0}", myOrange)
End Sub 'Main
End Class 'ParseTest
[C#]
using System;
public class ParseTest {
[FlagsAttribute]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main() {
Console.WriteLine("The entries of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
Console.WriteLine();
Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
Console.WriteLine("The myOrange value has the combined entries of {0}", myOrange);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
[FlagsAttribute]
__value enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
int main() {
Console::WriteLine("The entries of the Colors Enum are:");
Array* a = Enum::GetNames(__typeof(Colors));
Int32 i = 0;
while(i < a->Length){
Object* o = a->GetValue(i);
Console::WriteLine(o->ToString());
i++;
}
Console::WriteLine();
Object* myOrange = Enum::Parse(__typeof(Colors), "Red, Yellow");
Console::WriteLine("The myOrange value has the combined entries of {0}", myOrange);
}
[JScript]
import System;
public class ParseTest {
FlagsAttribute
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static function Main() {
Console.WriteLine("The entries of the Colors Enum are:");
for(var i : int in Enum.GetNames(Colors))
Console.WriteLine(Enum.GetNames(Colors).GetValue(i));
Console.WriteLine();
var myOrange : Colors = Colors(Enum.Parse(Colors, "Red, Yellow"));
Console.WriteLine("The myOrange value has the combined entries of {0}", myOrange);
}
}