Edit

Share via


Half.TryParse Method

Definition

Overloads

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Half)

Tries to parse a span of UTF-8 characters into a value.

TryParse(ReadOnlySpan<Char>, Half)

Converts the span representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

TryParse(String, Half)

Converts the string representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Half)

Tries to parse a span of UTF-8 characters into a value.

TryParse(ReadOnlySpan<Char>, IFormatProvider, Half)

Tries to parse a span of characters into a value.

TryParse(String, IFormatProvider, Half)

Tries to parse a string into a value.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Half)

Converts the span representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

TryParse(ReadOnlySpan<Byte>, Half)

Tries to convert a UTF-8 character span containing the string representation of a number to its half-precision floating-point number equivalent.

TryParse(String, NumberStyles, IFormatProvider, Half)

Converts the string representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs

Tries to parse a span of UTF-8 characters into a value.

C#
public static bool TryParse(ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style, IFormatProvider? provider, out Half result);

Parameters

utf8Text
ReadOnlySpan<Byte>

The span of UTF-8 characters to parse.

style
NumberStyles

A bitwise combination of number styles that can be present in utf8Text.

provider
IFormatProvider

An object that provides culture-specific formatting information about utf8Text.

result
Half

On return, contains the result of successfully parsing utf8Text or an undefined value on failure.

Returns

true if utf8Text was successfully parsed; otherwise, false.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryParse(ReadOnlySpan<Char>, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Converts the span representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

C#
public static bool TryParse(ReadOnlySpan<char> s, out Half result);

Parameters

s
ReadOnlySpan<Char>

A read-only span that contains a number to convert.

result
Half

When this method returns, contains the half-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or a default Half value if the conversion failed. The conversion fails if the s parameter is null or Empty or is not a number in a valid format. If s is a valid number less than MinValue, result contains NegativeInfinity. If s is a valid number greater than MaxValue, result contains PositiveInfinity. This parameter is treated as uninitialized.

Returns

true if s was converted successfully, false otherwise.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

TryParse(String, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Converts the string representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

C#
public static bool TryParse(string? s, out Half result);

Parameters

s
String

A string that contains a number to convert.

result
Half

When this method returns, contains the half-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or a default Half value if the conversion failed. The conversion fails if s is null or Empty or is not a number in a valid format. If s is a valid number less than MinValue, result contains NegativeInfinity. If s is a valid number greater than MaxValue, result contains PositiveInfinity. This parameter is treated as uninitialized.

Returns

true if the conversion was successful; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs

Tries to parse a span of UTF-8 characters into a value.

C#
public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Half result);

Parameters

utf8Text
ReadOnlySpan<Byte>

The span of UTF-8 characters to parse.

provider
IFormatProvider

An object that provides culture-specific formatting information about utf8Text.

result
Half

On return, contains the result of successfully parsing utf8Text or an undefined value on failure.

Returns

true if utf8Text was successfully parsed; otherwise, false.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryParse(ReadOnlySpan<Char>, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Tries to parse a span of characters into a value.

C#
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Half result);

Parameters

s
ReadOnlySpan<Char>

The span of characters to parse.

provider
IFormatProvider

An object that provides culture-specific formatting information about s.

result
Half

When this method returns, contains the result of successfully parsing s, or an undefined value on failure.

Returns

true if s was successfully parsed; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9

TryParse(String, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Tries to parse a string into a value.

C#
public static bool TryParse(string? s, IFormatProvider? provider, out Half result);

Parameters

s
String

The string to parse.

provider
IFormatProvider

An object that provides culture-specific formatting information about s.

result
Half

When this method returns, contains the result of successfully parsing s or an undefined value on failure.

Returns

true if s was successfully parsed; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET 7, 8, 9

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Converts the span representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

C#
public static bool TryParse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style, IFormatProvider? provider, out Half result);

Parameters

s
ReadOnlySpan<Char>

A read-only span that contains a number to convert.

style
NumberStyles

A bitwise combination of enumeration values that indicates the permitted format of s.

provider
IFormatProvider

An object that supplies culture-specific formatting information about s.

result
Half

When this method returns, contains the half-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or a default Half value if the conversion failed. The conversion fails if s is not a number in a valid format. If s is a valid number less than MinValue, result contains NegativeInfinity. If s is a valid number greater than MaxValue, result contains PositiveInfinity. This parameter is treated as uninitialized.

Returns

true if the conversion was successful; otherwise, false.

Exceptions

style is not a NumberStyles value.

-or-

NumberStyles is the AllowHexSpecifier value.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

TryParse(ReadOnlySpan<Byte>, Half)

Source:
Half.cs
Source:
Half.cs

Tries to convert a UTF-8 character span containing the string representation of a number to its half-precision floating-point number equivalent.

C#
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Half result);

Parameters

utf8Text
ReadOnlySpan<Byte>

A read-only UTF-8 character span that contains the number to convert.

result
Half

When this method returns, contains a half-precision floating-point number equivalent of the numeric value or symbol contained in utf8Text if the conversion succeeded or zero if the conversion failed. The conversion fails if the utf8Text is Empty or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.

Returns

true if utf8Text was converted successfully; otherwise, false.

Applies to

.NET 9 and .NET 8
Product Versions
.NET 8, 9

TryParse(String, NumberStyles, IFormatProvider, Half)

Source:
Half.cs
Source:
Half.cs
Source:
Half.cs

Converts the string representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

C#
public static bool TryParse(string? s, System.Globalization.NumberStyles style, IFormatProvider? provider, out Half result);

Parameters

s
String

A string that contains a number to convert.

style
NumberStyles

A bitwise combination of enumeration values that indicates the permitted format of s.

provider
IFormatProvider

An object that supplies culture-specific formatting information about s.

result
Half

When this method returns, contains the half-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or a default Half value if the conversion failed. The conversion fails if s is null or Empty or is not a number in a valid format. If s is a valid number less than MinValue, result contains NegativeInfinity. If s is a valid number greater than MaxValue, result contains PositiveInfinity. This parameter is treated as uninitialized.

Returns

true if the conversion was successful; otherwise, false.

Exceptions

style is not a NumberStyles value.

-or-

NumberStyles is the AllowHexSpecifier value.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9