C# Int64 Parse(String, NumberStyles)
Description
Int64 Parse(String, NumberStyles)
converts the string
representation of a number in a specified style to its 64-bit signed integer
equivalent.
Syntax
Int64.Parse(String, NumberStyles)
has the following syntax.
public static long Parse(
string s,
NumberStyles style
)
Parameters
Int64.Parse(String, NumberStyles)
has the following parameters.
s
- A string containing a number to convert.style
- A bitwise combination of NumberStyles values that indicates the permitted format of s. A typical value to specify is Integer.
Returns
Int64.Parse(String, NumberStyles)
method returns A 64-bit signed integer equivalent to the number specified in s.
Example
The following example uses the Int64.Parse(String, NumberStyles) method to parse the string representations of several Int64 values.
/*from ww w .jav a2 s. c om*/
using System;
using System.Globalization;
public class ParseInt32
{
public static void Main()
{
Convert("123.0", NumberStyles.AllowDecimalPoint);
Convert("123.9", NumberStyles.AllowDecimalPoint);
Convert (" 123456", NumberStyles.None);
Convert(" $12,345,678.89", NumberStyles.AllowCurrencySymbol |
NumberStyles.Number);
Convert(" $12,345,678.90", NumberStyles.AllowCurrencySymbol |
NumberStyles.Number);
Convert("123E06", NumberStyles.AllowExponent);
Convert("1230E-02", NumberStyles.AllowExponent);
Convert("1230E-03", NumberStyles.AllowExponent);
Convert("-1,234,789", NumberStyles.AllowThousands);
Convert("(1,234,789)", NumberStyles.AllowThousands |
NumberStyles.AllowParentheses);
Convert("FFCA00A0", NumberStyles.HexNumber);
Convert("0xFFCA00A0", NumberStyles.HexNumber);
}
private static void Convert(string value, NumberStyles style)
{
try
{
long number = Int64.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
Console.WriteLine("Unable to convert '{0}'.", value);
}
catch (OverflowException)
{
Console.WriteLine("'{0}' is out of range of the Int64 type.", value);
}
}
}
The code above generates the following result.