UInt64::TryParse Method (String^, UInt64%)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

clsCompliantAlternativeM:System.Decimal.Parse(System.String)

Tries to convert the string representation of a number to its 64-bit unsigned integer equivalent. A return value indicates whether the conversion succeeded or failed.

This API is not CLS-compliant.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
[CLSCompliantAttribute(false)]
static bool TryParse(
	String^ s,
	[OutAttribute] unsigned long long% result
)

Parameters

s
Type: System::String^

A string that represents the number to convert.

result
Type: System::UInt64%

When this method returns, contains the 64-bit unsigned integer value that is equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or String::Empty, is not of the correct format, or represents a number less than UInt64::MinValue or greater than MaxValue. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.

Return Value

Type: System::Boolean

true if s was converted successfully; otherwise, false.

The TryParse(String^, UInt64%) method is like the Parse(String^) method, except that it does not throw an exception if the conversion fails. This method eliminates the need to use exception handling to test for a FormatException if s is invalid and cannot be successfully parsed.

The s parameter should be the string representation of a decimal number in the following form:

[ws][sign]digits[ws]

Elements in square brackets ([ and ]) are optional. The following table describes each element.

Element

Description

ws

Optional white space.

sign

An optional sign. Valid sign characters are determined by the NumberFormatInfo::NegativeSign and NumberFormatInfo::PositiveSign properties of the current culture.

digits

A sequence of decimal digits ranging from 0 to 9.

The s parameter is interpreted by using the NumberStyles::Integer style. In addition to the decimal digits, only leading and trailing spaces with a leading sign are allowed. To explicitly define the style elements with the culture-specific formatting information that can be present in s, call the TryParse(String^, NumberStyles, IFormatProvider^, UInt64%) method.

System_CAPS_noteNote

The string specified by the s parameter cannot contain any group separators or decimal separator, and it cannot have a fractional portion.

The s parameter is parsed using the formatting information in a NumberFormatInfo object initialized for the current system culture. For more information, see NumberFormatInfo::CurrentInfo.

This overload interprets all digits in the s parameter as decimal digits. To parse the string representation of a hexadecimal number, call the TryParse(String^, NumberStyles, IFormatProvider^, UInt64%) overload instead.

The following example calls the TryParse(String^, UInt64%) method once for each element in a string array.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: