Boolean.Parse 方法

定義

多載

Parse(ReadOnlySpan<Char>)

將代表邏輯值的指定範圍轉換為其對等 Boolean

Parse(String)

將指定之邏輯值的字串表示,轉換為相等的 Boolean

Parse(ReadOnlySpan<Char>)

Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs

將代表邏輯值的指定範圍轉換為其對等 Boolean

public:
 static bool Parse(ReadOnlySpan<char> value);
public static bool Parse (ReadOnlySpan<char> value);
static member Parse : ReadOnlySpan<char> -> bool
Public Shared Function Parse (value As ReadOnlySpan(Of Char)) As Boolean

參數

value
ReadOnlySpan<Char>

範圍,其包含代表所要轉換值的字元。

傳回

如果 value 等於 TrueString,則為 true;如果 value 等於 FalseString 則為 false

適用於

Parse(String)

Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs

將指定之邏輯值的字串表示,轉換為相等的 Boolean

public:
 static bool Parse(System::String ^ value);
public static bool Parse (string value);
static member Parse : string -> bool
Public Shared Function Parse (value As String) As Boolean

參數

value
String

字串,包含要轉換的值。

傳回

如果 value 等於 TrueString,則為 true;如果 value 等於 FalseString 則為 false

例外狀況

valuenull

value 不等於 TrueStringFalseString

範例

下列程式碼範例說明 方法的使用 Parse 方式。

Boolean val;
String^ input;
input = Boolean::TrueString;
val = Boolean::Parse( input );
Console::WriteLine(  "'{0}' parsed as {1}", input, val );
// The example displays the following output:
//       'True' parsed as True
bool val;
string input;

input = bool.TrueString;
val = bool.Parse(input);
Console.WriteLine("'{0}' parsed as {1}", input, val);
// The example displays the following output:
//       'True' parsed as True
let input = bool.TrueString
let value = bool.Parse input
printfn $"'{input}' parsed as {value}"
// The example displays the following output:
//       'True' parsed as True
Dim val As Boolean
Dim input As String

input = Boolean.TrueString
val = Boolean.Parse(input)
Console.WriteLine("'{0}' parsed as {1}", input, val)
' The example displays the following output:
'       'True' parsed as True

備註

value參數前面或尾端有空白字元,必須包含 TrueStringFalseString ,否則會擲回例外狀況。 此比較不區分大小寫。

另請參閱

適用於