Saturday, November 7, 2009

Method to check whether input is interger or not

private bool IsInteger(string strInput)
{
try
{
int.parse(strInput);
return true;
}
catch(Exception ex)
{
return false;
}
}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. one more way:

    private bool IsInteger(string strInput)
    {
    int i=0;
    return int.TryParse(strInput,out i);
    }

    ReplyDelete