C# UInt64 TryParse(String, UInt64)

Description

UInt64 TryParse(String, UInt64) 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.

Syntax

UInt64.TryParse(String, UInt64) has the following syntax.


[CLSCompliantAttribute(false)]/*  w ww. ja v a 2 s  . c  om*/
public static bool TryParse(
  string s,
  out ulong result
)

Parameters

UInt64.TryParse(String, UInt64) has the following parameters.

  • s - A string that represents the number to convert.
  • result - 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.

Returns

UInt64.TryParse(String, UInt64) method returns true if s was converted successfully; otherwise, false.

Example

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


/*w  ww .  jav a2 s .  c  om*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    string[] numericStrings = { "1234.8", "+1234.7", "23423.", 
                                "   23423423  ", "(0)", "-0", "+1234234", 
                                "18-", "123423", "31,234", "  2342344 ",  
                                "00723400" };
    ulong number;
    foreach (string numericString in numericStrings)
    {
       if (UInt64.TryParse(numericString, out number)) 
          Console.WriteLine("Converted '{0}' to {1}.", numericString, number);
       else
          Console.WriteLine("Cannot convert '{0}' to a UInt64.", numericString);
    }

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version