Parse string to integer and NumberStyles : NumberStyles « Data Types « C# / C Sharp






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);
      }
   }
}

   
    
  








Related examples in the same category

1.Int32.Parse (String, NumberStyles)
2.Int32.Parse(String, NumberStyles, IFormatProvider)
3.Int32.TryParse Method (String, NumberStyles, IFormatProvider, Int32)
4.Integer NumberStyles.None
5.Integer NumberStyles.AllowLeadingSign
6.NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign
7.NumberStyles.Integer
8.NumberStyles.Integer | NumberStyles.AllowCurrencySymbol
9.NumberStyles.Integer | NumberStyles.AllowThousands
10.NumberStyles.Integer | NumberStyles.AllowExponent
11.Parse with NumberStyles.HexNumber
12.Parse currency value using en-GB culture.
13.NumberStyles.Integer | NumberStyles.AllowDecimalPoint
14.NumberStyles.Integer | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign
15.NumberStyles.HexNumber