Mega Code Archive

 
Categories / C# / Data Types
 

Converts string to integer

using System; public class ParseInt32 {    public static void Main()    {       Convert("179");    }    private static void Convert(string value)    {       try       {          int number = Int32.Parse(value);          Console.WriteLine("Converted '{0}' to {1}.", value, number);       }       catch (FormatException)       {          Console.WriteLine("Unable to convert '{0}'.", value);       }    } }