In WinForm I need to check if the value in the TextBox is a number or not.
In PHP there is is_numeric
function. Is something similar available in .NET?
In WinForm I need to check if the value in the TextBox is a number or not.
In PHP there is is_numeric
function. Is something similar available in .NET?
I'd use TryParse to check
string str = "123";
int i;
if (int.TryParse(str, out i))
{
// it's an int
}
you should be able to do similar with other types, such as double
int val;
bool parsed = Int32.TryParse(input_str, out val);
Gives you both if it's a valid int and the result of parsing it as int as well (in val)
int number;
string str="!23";
if(int.TryParse(str, out number))
{
//do something
}
if you are 100% sure its an int you can use:
int.Parse(str);
or
Convert.ToInt32(str);
it will cast an execption if its not an int