Parse string to integer and NumberStyles
using System; using System.Globalization; public class Example { public static void Main() { string string2 = "FFFFFF"; try { int number2 = Int32.Parse(string2,System.Globalization.NumberStyles.HexNumber); Console.WriteLine(number2); } catch (OverflowException) { Console.WriteLine("'{0}' is out of range of a 32-bit integer.", string2); } catch (FormatException) { Console.WriteLine("The format of '{0}' is invalid.", string2); } } }