Enum.Parse Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengonversi representasi string nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara.
Overload
Parse(Type, ReadOnlySpan<Char>) |
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. |
Parse(Type, String) |
Mengonversi representasi string nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. |
Parse(Type, ReadOnlySpan<Char>, Boolean) |
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil. |
Parse(Type, String, Boolean) |
Mengonversi representasi string nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil. |
Parse<TEnum>(String, Boolean) |
Mengonversi representasi string dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh |
Parse<TEnum>(ReadOnlySpan<Char>, Boolean) |
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh |
Parse<TEnum>(ReadOnlySpan<Char>) |
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh |
Parse<TEnum>(String) |
Mengonversi representasi string dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh |
Parse(Type, ReadOnlySpan<Char>)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara.
public:
static System::Object ^ Parse(Type ^ enumType, ReadOnlySpan<char> value);
public static object Parse (Type enumType, ReadOnlySpan<char> value);
static member Parse : Type * ReadOnlySpan<char> -> obj
Public Shared Function Parse (enumType As Type, value As ReadOnlySpan(Of Char)) As Object
Parameter
- enumType
- Type
Jenis enumerasi.
- value
- ReadOnlySpan<Char>
Rentang yang berisi nama atau nilai yang akan dikonversi.
Mengembalikan
Objek jenis enumType
yang nilainya diwakili oleh value
.
Pengecualian
enumType
adalah null
.
enumType
bukan .Enum
value
adalah string kosong atau hanya berisi spasi kosong.
value
adalah nama, tetapi bukan salah satu konstanta bernama yang ditentukan untuk enumerasi.
value
berada di luar rentang jenis yang mendasar dari enumType
.
.NET 8 dan versi yang lebih baru: enumType
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Parse(Type, String)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi representasi string nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara.
public:
static System::Object ^ Parse(Type ^ enumType, System::String ^ value);
public static object Parse (Type enumType, string value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object Parse (Type enumType, string value);
static member Parse : Type * string -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member Parse : Type * string -> obj
Public Shared Function Parse (enumType As Type, value As String) As Object
Parameter
- enumType
- Type
Jenis enumerasi.
- value
- String
String yang berisi nama atau nilai yang akan dikonversi.
Mengembalikan
Objek jenis enumType
yang nilainya diwakili oleh value
.
- Atribut
Pengecualian
enumType
atau value
adalah null
.
enumType
bukan .Enum
-atau-
value
adalah string kosong atau hanya berisi spasi kosong.
-atau-
value
adalah nama, tetapi bukan salah satu konstanta bernama yang ditentukan untuk enumerasi.
value
berada di luar rentang jenis yang mendasar dari enumType
.
.NET 8 dan versi yang lebih baru: enumType
adalah jenis enumerasi yang didukung Boolean.
Contoh
Contoh berikut menggunakan Parse(Type, String) metode untuk mengurai array string yang dibuat dengan memanggil GetNames metode . Ini juga menggunakan Parse(Type, String) metode untuk mengurai nilai enumerasi yang terdiri dari bidang bit.
using namespace System;
[Flags]
enum class Colors
{
Red = 1,
Green = 2,
Blue = 4,
Yellow = 8
};
int main()
{
Console::WriteLine( "The entries of the Colors enumeration are:" );
Array^ a = Enum::GetNames( Colors::typeid );
Int32 i = 0;
while ( i < a->Length )
{
Object^ o = a->GetValue( i );
Console::WriteLine( o->ToString() );
i++;
}
Console::WriteLine();
Object^ orange = Enum::Parse( Colors::typeid, "Red, Yellow" );
Console::WriteLine("The orange value has the combined entries of {0}", orange );
}
/*
This code example produces the following results:
The entries of the Colors Enum are:
Red
Green
Blue
Yellow
The orange value has the combined entries of Red, Yellow
*/
using System;
public class ParseTest
{
[Flags]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main()
{
Console.WriteLine("The entries of the Colors enumeration are:");
foreach (string colorName in Enum.GetNames(typeof(Colors)))
{
Console.WriteLine("{0} = {1:D}", colorName,
Enum.Parse(typeof(Colors), colorName));
}
Console.WriteLine();
Colors orange = (Colors) Enum.Parse(typeof(Colors), "Red, Yellow");
Console.WriteLine("The orange value {0:D} has the combined entries of {0}",
orange);
}
}
/*
This code example produces the following results:
The entries of the Colors Enum are:
Red = 1
Green = 2
Blue = 4
Yellow = 8
The orange value 9 has the combined entries of Red, Yellow
*/
open System
[<Flags>]
type Colors =
| Red = 1
| Green = 2
| Blue = 4
| Yellow = 8
printfn "The entries of the Colors enumeration are:"
for colorName in Enum.GetNames typeof<Colors> do
printfn $"{colorName} = {Enum.Parse(typeof<Colors>, colorName):D}"
printfn ""
let orange = Enum.Parse(typeof<Colors>, "Red, Yellow") :?> Colors
printfn $"The orange value {orange:D} has the combined entries of {orange}"
// This code example produces the following results:
// The entries of the Colors Enum are:
// Red = 1
// Green = 2
// Blue = 4
// Yellow = 8
//
// The orange value 9 has the combined entries of Red, Yellow
Public Class ParseTest
<Flags()> _
Enum Colors
Red = 1
Green = 2
Blue = 4
Yellow = 8
End Enum
Public Shared Sub Main()
Console.WriteLine("The entries of the Colors enumeration are:")
Dim colorName As String
For Each colorName In [Enum].GetNames(GetType(Colors))
Console.WriteLine("{0} = {1:D}", colorName, [Enum].Parse(GetType(Colors), colorName))
Next
Console.WriteLine()
Dim orange As Colors = CType([Enum].Parse(GetType(Colors), "Red, Yellow"), Colors)
Console.WriteLine("The orange value {0:D} has the combined entries of {0}", orange)
End Sub
End Class
'This example displays the following output:
'
'The entries of the Colors Enum are:
'Red = 1
'Green = 2
'Blue = 4
'Yellow = 8
'
'The myOrange value 9 has the combined entries of Red, Yellow
'
Keterangan
Parameter value
berisi representasi string dari nilai dasar anggota enumerasi atau konstanta bernama, atau daftar konstanta bernama yang dibatasi oleh koma (,). Satu atau beberapa spasi kosong dapat mendahului atau mengikuti setiap nilai, nama, atau koma di value
. Jika value
adalah daftar, nilai yang dikembalikan adalah nilai dari nama yang ditentukan yang dikombinasikan dengan operasi bitwise OR
.
Jika value
adalah nama yang tidak sesuai dengan konstanta enumType
bernama , metode akan melemparkan ArgumentException. Jika value
adalah representasi string bilangan bulat yang tidak mewakili nilai enumType
enumerasi yang mendasar, metode mengembalikan anggota enumerasi yang nilai value
yang mendasarnya dikonversi ke jenis integral. Jika perilaku ini tidak diinginkan, panggil IsDefined metode untuk memastikan bahwa representasi string tertentu dari bilangan bulat sebenarnya adalah anggota .enumType
Contoh berikut mendefinisikan Colors
enumerasi, memanggil Parse(Type, String) metode untuk mengonversi string ke nilai enumerasi yang sesuai, dan memanggil metode untuk memastikan bahwa nilai integral tertentu adalah nilai yang mendasar IsDefined dalam Colors
enumerasi.
using System;
[Flags] enum Colors { None=0, Red = 1, Green = 2, Blue = 4 };
public class Example
{
public static void Main()
{
string[] colorStrings = { "0", "2", "8", "blue", "Blue", "Yellow", "Red, Green" };
foreach (string colorString in colorStrings)
{
try {
Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString);
if (Enum.IsDefined(typeof(Colors), colorValue) | colorValue.ToString().Contains(","))
Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString());
else
Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString);
}
catch (ArgumentException) {
Console.WriteLine("'{0}' is not a member of the Colors enumeration.", colorString);
}
}
}
}
// The example displays the following output:
// Converted '0' to None.
// Converted '2' to Green.
// 8 is not an underlying value of the Colors enumeration.
// 'blue' is not a member of the Colors enumeration.
// Converted 'Blue' to Blue.
// 'Yellow' is not a member of the Colors enumeration.
// Converted 'Red, Green' to Red, Green.
open System
[<Flags>]
type Colors =
| None = 0
| Red = 1
| Green = 2
| Blue = 4
let colorStrings = [ "0"; "2"; "8"; "blue"; "Blue"; "Yellow"; "Red, Green" ]
for colorString in colorStrings do
try
let colorValue = Enum.Parse(typeof<Colors>, colorString) :?> Colors
if Enum.IsDefined(typeof<Colors>, colorValue) || (string colorValue).Contains "," then
printfn $"Converted '{colorString}' to {colorValue}."
else
printfn $"{colorString} is not an underlying value of the Colors enumeration."
with :? ArgumentException ->
printfn $"'{colorString}' is not a member of the Colors enumeration."
// The example displays the following output:
// Converted '0' to None.
// Converted '2' to Green.
// 8 is not an underlying value of the Colors enumeration.
// 'blue' is not a member of the Colors enumeration.
// Converted 'Blue' to Blue.
// 'Yellow' is not a member of the Colors enumeration.
// Converted 'Red, Green' to Red, Green.
<Flags> Enum Colors As Integer
None = 0
Red = 1
Green = 2
Blue = 4
End Enum
Module Example
Public Sub Main()
Dim colorStrings() As String = {"0", "2", "8", "blue", "Blue", "Yellow", "Red, Green"}
For Each colorString As String In colorStrings
Try
Dim colorValue As Colors = CType([Enum].Parse(GetType(Colors), colorString), Colors)
If [Enum].IsDefined(GetType(Colors), colorValue) Or colorValue.ToString().Contains(",") Then
Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString())
Else
Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString)
End If
Catch e As ArgumentException
Console.WriteLine("'{0}' is not a member of the Colors enumeration.", colorString)
End Try
Next
End Sub
End Module
' The example displays the following output:
' Converted '0' to None.
' Converted '2' to Green.
' 8 is not an underlying value of the Colors enumeration.
' 'blue' is not a member of the Colors enumeration.
' Converted 'Blue' to Blue.
' 'Yellow' is not a member of the Colors enumeration.
' Converted 'Red, Green' to Red, Green.
Operasi ini peka huruf besar/kecil.
Lihat juga
Berlaku untuk
Parse(Type, ReadOnlySpan<Char>, Boolean)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil.
public:
static System::Object ^ Parse(Type ^ enumType, ReadOnlySpan<char> value, bool ignoreCase);
public static object Parse (Type enumType, ReadOnlySpan<char> value, bool ignoreCase);
static member Parse : Type * ReadOnlySpan<char> * bool -> obj
Public Shared Function Parse (enumType As Type, value As ReadOnlySpan(Of Char), ignoreCase As Boolean) As Object
Parameter
- enumType
- Type
Jenis enumerasi.
- value
- ReadOnlySpan<Char>
Rentang yang berisi nama atau nilai yang akan dikonversi.
- ignoreCase
- Boolean
true
untuk mengabaikan kasus; false
untuk memperhatikan kasus.
Mengembalikan
Objek jenis enumType
yang nilainya diwakili oleh value
.
Pengecualian
enumType
adalah null
.
enumType
bukan .Enum
value
adalah string kosong atau hanya berisi spasi kosong.
value
adalah nama, tetapi bukan salah satu konstanta bernama yang ditentukan untuk enumerasi.
value
berada di luar rentang jenis yang mendasar dari enumType
.NET 8 dan versi yang lebih baru: enumType
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Parse(Type, String, Boolean)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi representasi string nama atau nilai numerik dari satu atau beberapa konstanta enumerasi menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil.
public:
static System::Object ^ Parse(Type ^ enumType, System::String ^ value, bool ignoreCase);
public static object Parse (Type enumType, string value, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public static object Parse (Type enumType, string value, bool ignoreCase);
static member Parse : Type * string * bool -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member Parse : Type * string * bool -> obj
Public Shared Function Parse (enumType As Type, value As String, ignoreCase As Boolean) As Object
Parameter
- enumType
- Type
Jenis enumerasi.
- value
- String
String yang berisi nama atau nilai yang akan dikonversi.
- ignoreCase
- Boolean
true
untuk mengabaikan kasus; false
untuk memperhatikan kasus.
Mengembalikan
Objek jenis enumType
yang nilainya diwakili oleh value
.
- Atribut
Pengecualian
enumType
atau value
adalah null
.
enumType
bukan .Enum
-atau-
value
adalah string kosong ("") atau hanya berisi spasi kosong.
-atau-
value
adalah nama, tetapi bukan salah satu konstanta bernama yang ditentukan untuk enumerasi.
value
berada di luar rentang jenis yang mendasar dari enumType
.
.NET 8 dan versi yang lebih baru: enumType
adalah jenis enumerasi yang didukung Boolean.
Contoh
Contoh berikut menggunakan Parse(Type, String, Boolean) metode untuk mengurai array string yang dibuat dengan memanggil GetNames metode . Ini juga menggunakan Parse(Type, String) metode untuk mengurai nilai enumerasi yang terdiri dari bidang bit.
using System;
[Flags] enum Colors { None=0, Red = 1, Green = 2, Blue = 4 };
public class Example
{
public static void Main()
{
string[] colorStrings = { "0", "2", "8", "blue", "Blue", "Yellow", "Red, Green" };
foreach (string colorString in colorStrings)
{
try {
Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString, true);
if (Enum.IsDefined(typeof(Colors), colorValue) | colorValue.ToString().Contains(","))
Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString());
else
Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString);
}
catch (ArgumentException) {
Console.WriteLine("{0} is not a member of the Colors enumeration.", colorString);
}
}
}
}
// The example displays the following output:
// Converted '0' to None.
// Converted '2' to Green.
// 8 is not an underlying value of the Colors enumeration.
// Converted 'blue' to Blue.
// Converted 'Blue' to Blue.
// Yellow is not a member of the Colors enumeration.
// Converted 'Red, Green' to Red, Green.
open System
[<Flags>]
type Colors =
| None = 0
| Red = 1
| Green = 2
| Blue = 4
let colorStrings = [ "0"; "2"; "8"; "blue"; "Blue"; "Yellow"; "Red, Green" ]
for colorString in colorStrings do
try
let colorValue = Enum.Parse(typeof<Colors>, colorString, true) :?> Colors
if Enum.IsDefined(typeof<Colors>, colorValue) || (string colorValue).Contains "," then
printfn $"Converted '{colorString}' to {colorValue}."
else
printfn $"{colorString} is not an underlying value of the Colors enumeration."
with :? ArgumentException ->
printfn $"{colorString} is not a member of the Colors enumeration."
// The example displays the following output:
// Converted '0' to None.
// Converted '2' to Green.
// 8 is not an underlying value of the Colors enumeration.
// Converted 'blue' to Blue.
// Converted 'Blue' to Blue.
// Yellow is not a member of the Colors enumeration.
// Converted 'Red, Green' to Red, Green.
<Flags> Enum Colors As Integer
None = 0
Red = 1
Green = 2
Blue = 4
End Enum
Module Example
Public Sub Main()
Dim colorStrings() As String = {"0", "2", "8", "blue", "Blue", "Yellow", "Red, Green"}
For Each colorString As String In colorStrings
Try
Dim colorValue As Colors = CType([Enum].Parse(GetType(Colors), colorString, True), Colors)
If [Enum].IsDefined(GetType(Colors), colorValue) Or colorValue.ToString().Contains(",") Then
Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString())
Else
Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString)
End If
Catch e As ArgumentException
Console.WriteLine("{0} is not a member of the Colors enumeration.", colorString)
End Try
Next
End Sub
End Module
' The example displays the following output:
' Converted '0' to None.
' Converted '2' to Green.
' 8 is not an underlying value of the Colors enumeration.
' Converted 'blue' to Blue.
' Converted 'Blue' to Blue.
' Yellow is not a member of the Colors enumeration.
' Converted 'Red, Green' to Red, Green.
Keterangan
Parameter value
berisi representasi string dari nilai dasar anggota enumerasi atau konstanta bernama, atau daftar konstanta bernama yang dibatasi oleh koma (,). Satu atau beberapa spasi kosong dapat mendahului atau mengikuti setiap nilai, nama, atau koma di value
. Jika value
adalah daftar, nilai yang dikembalikan adalah nilai dari nama yang ditentukan yang dikombinasikan dengan operasi bitwise OR
.
Jika value
adalah nama yang tidak sesuai dengan konstanta enumType
bernama , metode akan melemparkan ArgumentException. Jika value
adalah representasi string bilangan bulat yang tidak mewakili nilai enumType
enumerasi yang mendasar, metode mengembalikan anggota enumerasi yang nilai value
yang mendasarnya dikonversi ke jenis integral. Jika perilaku ini tidak diinginkan, panggil IsDefined metode untuk memastikan bahwa representasi string tertentu dari bilangan bulat sebenarnya adalah anggota .enumType
Contoh berikut mendefinisikan Colors
enumerasi, memanggil Parse(Type, String, Boolean) metode untuk mengonversi string ke nilai enumerasi yang sesuai, dan memanggil metode untuk memastikan bahwa nilai integral tertentu adalah nilai yang mendasar IsDefined dalam Colors
enumerasi.
Parameter ignoreCase
menentukan apakah operasi ini peka huruf besar/kecil.
Lihat juga
Berlaku untuk
Parse<TEnum>(String, Boolean)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi representasi string dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh TEnum
menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil.
public:
generic <typename TEnum>
where TEnum : value class static TEnum Parse(System::String ^ value, bool ignoreCase);
public static TEnum Parse<TEnum> (string value, bool ignoreCase) where TEnum : struct;
static member Parse : string * bool -> 'Enum (requires 'Enum : struct)
Public Shared Function Parse(Of TEnum As Structure) (value As String, ignoreCase As Boolean) As TEnum
Jenis parameter
- TEnum
Jenis enumerasi.
Parameter
- value
- String
String yang berisi nama atau nilai yang akan dikonversi.
- ignoreCase
- Boolean
true
untuk mengabaikan kasus; false
untuk memperhatikan kasus.
Mengembalikan
Objek jenis TEnum
yang nilainya diwakili oleh value
.
Pengecualian
TEnum
bukan tipe Enum .
value
adalah null
.
value
tidak berisi informasi enumerasi.
.NET 8 dan versi yang lebih baru: TEnum
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Parse<TEnum>(ReadOnlySpan<Char>, Boolean)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh TEnum
menjadi objek enumerasi yang setara. Parameter menentukan apakah operasi tidak peka huruf besar/kecil.
public:
generic <typename TEnum>
where TEnum : value class static TEnum Parse(ReadOnlySpan<char> value, bool ignoreCase);
public static TEnum Parse<TEnum> (ReadOnlySpan<char> value, bool ignoreCase) where TEnum : struct;
static member Parse : ReadOnlySpan<char> * bool -> 'Enum (requires 'Enum : struct)
Public Shared Function Parse(Of TEnum As Structure) (value As ReadOnlySpan(Of Char), ignoreCase As Boolean) As TEnum
Jenis parameter
- TEnum
Jenis enumerasi.
Parameter
- value
- ReadOnlySpan<Char>
Rentang yang berisi nama atau nilai yang akan dikonversi.
- ignoreCase
- Boolean
true
untuk mengabaikan kasus; false
untuk memperhatikan kasus.
Mengembalikan
TEnum
Objek jenis TEnum
yang nilainya diwakili oleh value
.
Pengecualian
TEnum
bukan tipe Enum .
value
tidak berisi informasi enumerasi.
.NET 8 dan versi yang lebih baru: TEnum
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Parse<TEnum>(ReadOnlySpan<Char>)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi rentang representasi karakter dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh TEnum
menjadi objek enumerasi yang setara.
public:
generic <typename TEnum>
where TEnum : value class static TEnum Parse(ReadOnlySpan<char> value);
public static TEnum Parse<TEnum> (ReadOnlySpan<char> value) where TEnum : struct;
static member Parse : ReadOnlySpan<char> -> 'Enum (requires 'Enum : struct)
Public Shared Function Parse(Of TEnum As Structure) (value As ReadOnlySpan(Of Char)) As TEnum
Jenis parameter
- TEnum
Jenis enumerasi.
Parameter
- value
- ReadOnlySpan<Char>
Rentang yang berisi nama atau nilai yang akan dikonversi.
Mengembalikan
TEnum
Objek jenis TEnum
yang nilainya diwakili oleh value
.
Pengecualian
TEnum
bukan tipe Enum .
value
tidak berisi informasi enumerasi.
.NET 8 dan versi yang lebih baru: TEnum
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Parse<TEnum>(String)
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
- Sumber:
- Enum.cs
Mengonversi representasi string dari nama atau nilai numerik dari satu atau beberapa konstanta enumerasi yang ditentukan oleh TEnum
menjadi objek enumerasi yang setara.
public:
generic <typename TEnum>
where TEnum : value class static TEnum Parse(System::String ^ value);
public static TEnum Parse<TEnum> (string value) where TEnum : struct;
static member Parse : string -> 'Enum (requires 'Enum : struct)
Public Shared Function Parse(Of TEnum As Structure) (value As String) As TEnum
Jenis parameter
- TEnum
Jenis enumerasi.
Parameter
- value
- String
String yang berisi nama atau nilai yang akan dikonversi.
Mengembalikan
Objek jenis TEnum
yang nilainya diwakili oleh value
.
Pengecualian
TEnum
bukan tipe Enum .
value
adalah null
.
value
tidak berisi informasi enumerasi.
.NET 8 dan versi yang lebih baru: TEnum
adalah jenis enumerasi yang didukung Boolean.
Berlaku untuk
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk