Export (0) Print
Expand All

UInt64.Parse Method (String)

Converts the string representation of a number to its 64-bit unsigned integer equivalent.

This API is not CLS-compliant. The CLS-compliant alternative is Parse.

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

[CLSCompliantAttribute(false)]
public static ulong Parse(
	string s
)

Parameters

s
Type: System.String

A string that represents the number to convert.

Return Value

Type: System.UInt64
A 64-bit unsigned integer equivalent to the number contained in s.

ExceptionCondition
ArgumentNullException

The s parameter is null.

FormatException

The s parameter is not in the correct format.

OverflowException

The s parameter represents a number less than UInt64.MinValue or greater than UInt64.MaxValue.

The s parameter should be the string representation of a 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. However, the negative sign symbol can be used only with zero; otherwise, the method throws an OverflowException.

digits

A sequence of digits ranging from 0 to 9. Any leading zeros are ignored.

NoteNote

The string specified by the s parameter is interpreted by using the NumberStyles.Integer style. It cannot contain any group separators or decimal separator, and it cannot have a decimal portion.

The s parameter is parsed by using the formatting information in a System.Globalization.NumberFormatInfo object that is initialized for the current system culture. For more information, see NumberFormatInfo.CurrentInfo. To parse a string by using the formatting information of a specific culture, use the Parse(String, IFormatProvider) method.

The following example uses the Parse method to parse an array of string values.

string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
                    "0xFA1B", "163042", "-10", "14065839182",
                    "16e07", "134985.0", "-12034" };
foreach (string value in values)
{
   try {
      ulong number = UInt64.Parse(value); 
      Console.WriteLine("{0} --> {1}", value, number);
   }
   catch (FormatException) {
      Console.WriteLine("{0}: Bad Format", value);
   }   
   catch (OverflowException) {
      Console.WriteLine("{0}: Overflow", value);   
   }  
}
// The example displays the following output: 
//       +13230 --> 13230 
//       -0 --> 0 
//       1,390,146: Bad Format 
//       $190,235,421,127: Bad Format 
//       0xFA1B: Bad Format 
//       163042 --> 163042 
//       -10: Overflow 
//       14065839182 --> 14065839182 
//       16e07: Bad Format 
//       134985.0: Bad Format 
//       -12034: Overflow

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft