Check string is number or not in C#

Int.TryParse() method converts string into integer and if this conversion is not possible then it will return false means your inputted string is not number

string number = “1234”;
int a = 0;
bool isNumber = int.TryParse(number, out a);

if (isNumber == true)
{
            //string is valid number
}
else
{
           //Given string is not a number
}

2 thoughts on “Check string is number or not in C#

  • December 9, 2016 at 4:29 PM
    Permalink

    Very good written article. It will be supportive to everyone who usess it, as well as me. Keep doing what you are doing – for sure i will check out more posts.

    Reply
    • December 31, 2016 at 7:20 PM
      Permalink

      thanks for the compliment

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *