Enum.Parse Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Konwertuje ciąg znaków reprezentujący nazwę lub wartość liczbową jednej lub więcej stałych wyliczeniowych dla równoważnego obiektu wyliczanego.
Przeciążenia
Parse(Type, ReadOnlySpan<Char>) |
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej na równoważny obiekt wyliczany. |
Parse(Type, String) |
Konwertuje ciąg znaków reprezentujący nazwę lub wartość liczbową jednej lub więcej stałych wyliczeniowych dla równoważnego obiektu wyliczanego. |
Parse(Type, ReadOnlySpan<Char>, Boolean) |
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej na równoważny obiekt wyliczany. Parametr określa, czy operacja jest bez uwzględniania wielkości liter. |
Parse(Type, String, Boolean) |
Konwertuje ciąg znaków reprezentujący nazwę lub wartość liczbową jednej lub więcej stałych wyliczeniowych dla równoważnego obiektu wyliczanego. Parametr określa, czy operacja jest bez uwzględniania wielkości liter. |
Parse<TEnum>(String, Boolean) |
Konwertuje reprezentację ciągu nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez |
Parse<TEnum>(ReadOnlySpan<Char>, Boolean) |
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej określonej przez |
Parse<TEnum>(ReadOnlySpan<Char>) |
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej określonej przez |
Parse<TEnum>(String) |
Konwertuje reprezentację ciągu nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez |
Parse(Type, ReadOnlySpan<Char>)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej na równoważny obiekt wyliczany.
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
Parametry
- enumType
- Type
Typ wyliczenia.
- value
- ReadOnlySpan<Char>
Zakres zawierający nazwę lub wartość do przekonwertowania.
Zwraca
Obiekt typu enumType
, którego wartość jest reprezentowana przez value
.
Wyjątki
enumType
to null
.
enumType
nie jest .Enum
value
jest pustym ciągiem lub zawiera tylko białe znaki.
value
jest nazwą, ale nie jedną z nazwanych stałych zdefiniowanych dla wyliczenia.
value
znajduje się poza zakresem bazowego enumType
typu .
.NET 8 i nowsze wersje: enumType
jest typem wyliczenia opartego na wartości logicznej.
Dotyczy
Parse(Type, String)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje ciąg znaków reprezentujący nazwę lub wartość liczbową jednej lub więcej stałych wyliczeniowych dla równoważnego obiektu wyliczanego.
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
Parametry
- enumType
- Type
Typ wyliczenia.
- value
- String
Ciąg zawierający nazwę lub wartość do przekonwertowania.
Zwraca
Obiekt typu enumType
, którego wartość jest reprezentowana przez value
.
- Atrybuty
Wyjątki
enumType
lub value
ma wartość null
.
enumType
nie jest .Enum
-lub-
value
jest pustym ciągiem lub zawiera tylko białe znaki.
-lub-
value
jest nazwą, ale nie jedną z nazwanych stałych zdefiniowanych dla wyliczenia.
value
znajduje się poza zakresem bazowego enumType
typu .
.NET 8 i nowsze wersje: enumType
jest typem wyliczenia opartego na wartości logicznej.
Przykłady
W poniższym przykładzie użyto Parse(Type, String) metody , aby przeanalizować tablicę ciągów, które są tworzone przez wywołanie GetNames metody . Używa Parse(Type, String) również metody do analizowania wartości wyliczenia, która składa się z pola bitowego.
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
'
Uwagi
Parametr value
zawiera ciąg reprezentujący wartość bazową elementu członkowskiego wyliczenia lub nazwaną stałą albo listę nazwanych stałych rozdzielonych przecinkami (,). Co najmniej jedno puste spacje może poprzedzać lub podążać za każdą wartością, nazwą lub przecinkiem w pliku value
. Jeśli value
jest listą, wartość zwracana jest wartością określonych nazw w połączeniu z operacją bitową OR
.
Jeśli value
jest nazwą, która nie odpowiada nazwanej stałej enumType
, metoda zgłasza wartość ArgumentException. Jeśli value
jest reprezentacją ciągu liczby całkowitej, która nie reprezentuje bazowej wartości enumType
wyliczenia, metoda zwraca element członkowski wyliczenia, którego wartość bazowa jest value
konwertowana na typ całkowity. Jeśli to zachowanie jest niepożądane, wywołaj metodę IsDefined , aby upewnić się, że określona reprezentacja ciągu liczby całkowitej enumType
jest rzeczywiście elementem członkowskim . Poniższy przykład definiuje wyliczenie, wywołuje metodę Colors
, aby przekonwertować ciągi na odpowiadające im wartości wyliczenia i wywołuje IsDefined metodę w celu zapewnienia, że określone wartości całkowite są wartościami bazowymi w wyliczenieColors
.Parse(Type, String)
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.
W tej operacji jest uwzględniana wielkość liter.
Zobacz też
Dotyczy
Parse(Type, ReadOnlySpan<Char>, Boolean)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje zakres znaków reprezentujący nazwę lub wartość liczbową co najmniej jednej stałej wyliczanej na równoważny obiekt wyliczany. Parametr określa, czy operacja jest bez uwzględniania wielkości liter.
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
Parametry
- enumType
- Type
Typ wyliczenia.
- value
- ReadOnlySpan<Char>
Zakres zawierający nazwę lub wartość do przekonwertowania.
- ignoreCase
- Boolean
true
ignorować wielkość liter; false
w odniesieniu do sprawy.
Zwraca
Obiekt typu enumType
, którego wartość jest reprezentowana przez value
.
Wyjątki
enumType
to null
.
enumType
nie jest .Enum
value
jest pustym ciągiem lub zawiera tylko białe znaki.
value
jest nazwą, ale nie jedną z nazwanych stałych zdefiniowanych dla wyliczenia.
value
znajduje się poza zakresem bazowego typu enumType
.NET 8 i nowsze wersje: enumType
jest typem wyliczenia opartego na wartości logicznej.
Dotyczy
Parse(Type, String, Boolean)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje ciąg znaków reprezentujący nazwę lub wartość liczbową jednej lub więcej stałych wyliczeniowych dla równoważnego obiektu wyliczanego. Parametr określa, czy operacja jest bez uwzględniania wielkości liter.
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
Parametry
- enumType
- Type
Typ wyliczenia.
- value
- String
Ciąg zawierający nazwę lub wartość do przekonwertowania.
- ignoreCase
- Boolean
true
ignorować wielkość liter; false
w odniesieniu do sprawy.
Zwraca
Obiekt typu enumType
, którego wartość jest reprezentowana przez value
.
- Atrybuty
Wyjątki
enumType
lub value
ma wartość null
.
enumType
nie jest .Enum
-lub-
value
jest pustym ciągiem ("") lub zawiera tylko białe znaki.
-lub-
value
jest nazwą, ale nie jedną z nazwanych stałych zdefiniowanych dla wyliczenia.
value
znajduje się poza zakresem bazowego enumType
typu .
.NET 8 i nowsze wersje: enumType
jest typem wyliczenia opartego na wartości logicznej.
Przykłady
W poniższym przykładzie użyto Parse(Type, String, Boolean) metody , aby przeanalizować tablicę ciągów, które są tworzone przez wywołanie GetNames metody . Używa Parse(Type, String) również metody do analizowania wartości wyliczenia, która składa się z pola bitowego.
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.
Uwagi
Parametr value
zawiera ciąg reprezentujący wartość bazową elementu członkowskiego wyliczenia lub nazwaną stałą albo listę nazwanych stałych rozdzielonych przecinkami (,). Co najmniej jedno puste spacje może poprzedzać lub podążać za każdą wartością, nazwą lub przecinkiem w pliku value
. Jeśli value
jest listą, wartość zwracana jest wartością określonych nazw w połączeniu z operacją bitową OR
.
Jeśli value
jest nazwą, która nie odpowiada nazwanej stałej enumType
, metoda zgłasza wartość ArgumentException. Jeśli value
jest reprezentacją ciągu liczby całkowitej, która nie reprezentuje bazowej wartości enumType
wyliczenia, metoda zwraca element członkowski wyliczenia, którego wartość bazowa jest value
konwertowana na typ całkowity. Jeśli to zachowanie jest niepożądane, wywołaj metodę IsDefined , aby upewnić się, że określona reprezentacja ciągu liczby całkowitej enumType
jest rzeczywiście elementem członkowskim . Poniższy przykład definiuje wyliczenie, wywołuje metodę Colors
, aby przekonwertować ciągi na odpowiadające im wartości wyliczenia i wywołuje IsDefined metodę w celu zapewnienia, że określone wartości całkowite są wartościami bazowymi w wyliczenieColors
.Parse(Type, String, Boolean)
Parametr ignoreCase
określa, czy ta operacja uwzględnia wielkość liter.
Zobacz też
Dotyczy
Parse<TEnum>(String, Boolean)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje reprezentację ciągu nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez do TEnum
równoważnego obiektu wyliczonego. Parametr określa, czy operacja jest bez uwzględniania wielkości liter.
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
Parametry typu
- TEnum
Typ wyliczenia.
Parametry
- value
- String
Ciąg zawierający nazwę lub wartość do przekonwertowania.
- ignoreCase
- Boolean
true
ignorować wielkość liter; false
w odniesieniu do sprawy.
Zwraca
Obiekt typu TEnum
, którego wartość jest reprezentowana przez value
obiekt .
Wyjątki
TEnum
nie jest typem Enum .
value
to null
.
value
nie zawiera informacji wyliczenia.
.NET 8 i nowsze wersje: TEnum
jest typem wyliczenia opartego na wartości logicznej.
Dotyczy
Parse<TEnum>(ReadOnlySpan<Char>, Boolean)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje zakres znaków reprezentacji nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez do TEnum
równoważnego obiektu wyliczonego. Parametr określa, czy operacja jest bez uwzględniania wielkości liter.
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
Parametry typu
- TEnum
Typ wyliczenia.
Parametry
- value
- ReadOnlySpan<Char>
Zakres zawierający nazwę lub wartość do przekonwertowania.
- ignoreCase
- Boolean
true
ignorować wielkość liter; false
w odniesieniu do sprawy.
Zwraca
TEnum
Obiekt typu TEnum
, którego wartość jest reprezentowana przez value
obiekt .
Wyjątki
TEnum
nie jest typem Enum .
value
nie zawiera informacji wyliczenia.
.NET 8 i nowsze wersje: TEnum
jest typem wyliczania opartego na wartości logicznej.
Dotyczy
Parse<TEnum>(ReadOnlySpan<Char>)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje zakres znaków reprezentacji nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez do TEnum
równoważnego obiektu wyliczonego.
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
Parametry typu
- TEnum
Typ wyliczenia.
Parametry
- value
- ReadOnlySpan<Char>
Zakres zawierający nazwę lub wartość do przekonwertowania.
Zwraca
TEnum
Obiekt typu TEnum
, którego wartość jest reprezentowana przez value
obiekt .
Wyjątki
TEnum
nie jest typem Enum .
value
nie zawiera informacji wyliczenia.
.NET 8 i nowsze wersje: TEnum
jest typem wyliczania opartego na wartości logicznej.
Dotyczy
Parse<TEnum>(String)
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
- Źródło:
- Enum.cs
Konwertuje reprezentację ciągu nazwy lub wartości liczbowej co najmniej jednej wyliczonej stałej określonej przez do TEnum
równoważnego obiektu wyliczonego.
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
Parametry typu
- TEnum
Typ wyliczenia.
Parametry
- value
- String
Ciąg zawierający nazwę lub wartość do przekonwertowania.
Zwraca
Obiekt typu TEnum
, którego wartość jest reprezentowana przez value
obiekt .
Wyjątki
TEnum
nie jest typem Enum .
value
to null
.
value
nie zawiera informacji wyliczenia.
.NET 8 i nowsze wersje: TEnum
jest typem wyliczania opartego na wartości logicznej.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla