C# Convert ToUInt64(String, Int32)

Description

Convert ToUInt64(String, Int32) converts the string representation of a number in a specified base to an equivalent 64-bit unsigned integer.

Syntax

Convert.ToUInt64(String, Int32) has the following syntax.


[CLSCompliantAttribute(false)]// w  ww.j  a v a  2s  .  co  m
public static ulong ToUInt64(
  string value,
  int fromBase
)

Parameters

Convert.ToUInt64(String, Int32) has the following parameters.

  • value - A string that contains the number to convert.
  • fromBase - The base of the number in value, which must be 2, 8, 10, or 16.

Returns

Convert.ToUInt64(String, Int32) method returns A 64-bit unsigned integer that is equivalent to the number in value, or 0 (zero) if value is null.

Example


using System;/*from www .j  a  va2  s.  c  om*/
public class Example
{
   public static void Main()
   {
      string[] hexStrings = { "80000000", "0FFFFFFF", "F0000000", "00A3000", "D", 
                              "-13", "9AC61", "GAD", "FFFFFFFFFF" };

      foreach (string hexString in hexStrings)
      {
         Console.Write("{0,-12}  -->  ", hexString);
         try {
            uint number = Convert.ToUInt32(hexString, 16);
            Console.WriteLine("{0,18:N0}", number);
         }
         catch (FormatException) {
            Console.WriteLine("{0,18}", "Bad Format");
         }   
         catch (OverflowException)
         {
            Console.WriteLine("{0,18}", "Numeric Overflow");
         }   
         catch (ArgumentException) {
            Console.WriteLine("{0,18}", "Invalid in Base 16");
         }
      }                                            
   }
}

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