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.

返回

Boolean

如果 value 等效于 TrueString,则为 true;如果 value 等效于 FalseString,则为 falsetrue 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.

返回

Boolean

如果 value 等效于 TrueString,则为 true;如果 value 等效于 FalseString,则为 falsetrue if value is equivalent to TrueString; false if value is equivalent to FalseString.

例外

value 上声明的默认值为 nullvalue is null.

value 并不等效于 TrueStringFalseStringvalue is not equivalent to TrueString or FalseString.

示例

下面的代码示例演示方法的用法 ParseThe 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.

另请参阅

适用于

产品 已引入