C# Int64 Parse(String)

Description

Int64 Parse(String) converts the string representation of a number to its 64-bit signed integer equivalent.

Syntax

Int64.Parse(String) has the following syntax.


public static long Parse(
  string s
)

Parameters

Int64.Parse(String) has the following parameters.

  • s - A string containing a number to convert.

Returns

Int64.Parse(String) method returns A 64-bit signed integer equivalent to the number contained in s.

Example

The following example demonstrates how to convert a string value into a 64-bit signed integer value using the Int64.Parse(String) method.


using System;//w ww. j ava  2 s . c  om

public class ParseInt64
{
   public static void Main()
   {
      Convert("  123456  ");
      Convert(" -1234567 ");
      Convert(" +1234567 ");
      Convert("   1234.0   ");
      Convert("  123.4");
      Convert(String.Empty);
      Convert(((decimal) Int64.MaxValue) + 1.ToString());
   }

   private static void Convert(string value)
   {
      try
      {
         long number = Int64.Parse(value);
         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.", 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