C# UInt64 Parse(String, NumberStyles, IFormatProvider)

Description

UInt64 Parse(String, NumberStyles, IFormatProvider) converts the string representation of a number in a specified style and culture-specific format to its 64-bit unsigned integer equivalent.

Syntax

UInt64.Parse(String, NumberStyles, IFormatProvider) has the following syntax.


[CLSCompliantAttribute(false)]/*from   ww  w  .ja  v  a  2 s .c  o m*/
public static ulong Parse(
  string s,
  NumberStyles style,
  IFormatProvider provider
)

Parameters

UInt64.Parse(String, NumberStyles, IFormatProvider) has the following parameters.

  • s - A string that represents the number to convert. The string is interpreted by using the style specified by the style parameter.
  • style - A bitwise combination of enumeration values that indicates the style elements that can be present in s. A typical value to specify is Integer.
  • provider - An object that supplies culture-specific formatting information about s.

Returns

UInt64.Parse(String, NumberStyles, IFormatProvider) method returns A 64-bit unsigned integer equivalent to the number specified in s.

Example

The following example uses the Parse(String, NumberStyles, IFormatProvider) method to convert various string representations of numbers to 64-bit unsigned integer values.


using System;//www.j  a v a2s  .c o  m
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] cultureNames= { "en-US", "fr-FR" };
      NumberStyles[] styles= { NumberStyles.Integer,
                               NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
      string[] values = { "123423", "+123423.0", "+123423,0", "-123423.00",
                                 "-123423,00", "123423.1", "123423,1" };

      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         Console.WriteLine(ci.DisplayName);
         foreach (NumberStyles style in styles)
         {
            Console.WriteLine(style.ToString());
            foreach (string value in values)
            {
               try {
                  Console.WriteLine(UInt64.Parse(value, style, ci));
               }
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);
               }      
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt64 type.",
                                    value);
               }
            }
         }
      }                                    
   }
}

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