Boolean.Parse 方法

定義

多載

Parse(ReadOnlySpan<Char>)

將代表邏輯值的指定範圍轉換為其對等 BooleanConverts the specified span representation of a logical value to its Boolean equivalent.

Parse(String)

將指定之邏輯值的字串表示,轉換為相等的 BooleanConverts the specified string representation of a logical value to its Boolean equivalent.

Parse(ReadOnlySpan<Char>)

將代表邏輯值的指定範圍轉換為其對等 BooleanConverts the specified span representation of a logical value to its Boolean equivalent.

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>

範圍,其包含代表所要轉換值的字元。A span containing the characters representing the value to convert.

傳回

如果 true 等於 value,則為 TrueString;如果 false 等於 value 則為 FalseStringtrue if value is equivalent to TrueString; false if value is equivalent to FalseString.

Parse(String)

將指定之邏輯值的字串表示,轉換為相等的 BooleanConverts the specified string representation of a logical value to its Boolean equivalent.

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

字串,包含要轉換的值。A string containing the value to convert.

傳回

如果 true 等於 value,則為 TrueString;如果 false 等於 value 則為 FalseStringtrue if value is equivalent to TrueString; false if value is equivalent to FalseString.

例外狀況

valuenullvalue is null.

value 不等於 TrueStringFalseStringvalue is not equivalent to TrueString or FalseString.

範例

下列程式碼範例說明如何使用 Parse 方法。The following code example illustrates the use of Parse method.

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        
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 參數(選擇性地加上或 trailed 空白字元)必須包含 TrueStringFalseString;否則,就會擲回例外狀況。The value parameter, optionally preceded or trailed by white space, must contain either TrueString or FalseString; otherwise, an exception is thrown. 比較不區分大小寫。The comparison is case-insensitive.

另請參閱

適用於