Boolean.Parse 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
Parse(ReadOnlySpan<Char>) |
将逻辑值的指定范围表示形式转换为它的等效 Boolean。 |
Parse(String) |
将逻辑值的指定字符串表示形式转换为其等效的 Boolean。 |
- Source:
- Boolean.cs
- Source:
- Boolean.cs
- Source:
- Boolean.cs
将逻辑值的指定范围表示形式转换为它的等效 Boolean。
public:
static bool Parse(ReadOnlySpan<char> value);
C#
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
。
适用于
.NET 10 和其他版本
产品 | 版本 |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Standard | 2.1 |
- Source:
- Boolean.cs
- Source:
- Boolean.cs
- Source:
- Boolean.cs
将逻辑值的指定字符串表示形式转换为其等效的 Boolean。
public:
static bool Parse(System::String ^ value);
C#
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
。
例外
value
上声明的默认值为 null
。
value
并不等效于 TrueString 或 FalseString。
示例
下面的代码示例演示如何使用 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
C#
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
(可选)前面或尾随空格,必须包含 TrueString 或 FalseString;否则将引发异常。 比较不区分大小写。
另请参阅
适用于
.NET 10 和其他版本
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |