.NET API Documentation

System.Int32.Parse Method

Converts the string representation of a number to its 32-bit signed integer equivalent.

Namespace

System

Assembly

System.Runtime.dll

Syntax

public static int Parse(string s);
public static int Parse(string s, System.Globalization.NumberStyles style);
public static int Parse(string s, System.IFormatProvider provider);
public static int Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider provider);

Parameters

Return Value

The 32-bit signed integer equivalent of the number contained in s.

Exceptions

Remarks

The method uses the formatting conventions of the current culture unless a specific IFormatProvider is supplied. Leading and trailing white‑space characters are ignored.

Interactive Demo

Example

// C# example
try
{
    int number = Int32.Parse("12345");
    Console.WriteLine(number);
}
catch (FormatException)
{
    Console.WriteLine("Input string was not in a correct format.");
}
catch (OverflowException)
{
    Console.WriteLine("The number is too large or too small for an Int32.");
}