Sponsored Ad

Monday, March 22, 2010

How to Check Numeric Value in C# | IsNumeric() | Convert String to Integer Value

This utility helps you to check a value for integer values. Just pass input string  and it will return true if string is integer value and return false in case of non integer values.

int.Parse will through a exception if value is not integer.

There is another option you can try with

Int32.TryParse Method (string strCheck, int Result)

With this method you can convert string to int without any exception. input parameter for this method is string the original value and second is out parameter as result. if result have non zero value it means conversion successful and the given value is integer. and result for zero value indicate that the given string is non integer.

 

       /// <summary>
      /// Performs validation whether the passed in string is numeric.
      /// </summary>
      public static bool IsNumeric(string strCheck)
      {
          try
          {
              int.Parse(strCheck);
              return true;
          }
          catch
          {
              return false;
          }
      }

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers