How to check if value is number or string in c# [Resolved]

Posted by Allemahesh under C# on 7/15/2013 | Points: 10 | Views : 1598 | Status : [Member] [MVP] | Replies : 2
I have a value coming from text box. Now I want to check if this value is string or integer using c#. Can any one help me.




Responses

Posted by: Ssj_Kumar on: 7/15/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
string Value= "100A";
int Number;
if (!int.TryParse(Value, out Number))
{
label1.Text = "String";
}
else
{
label1.Text = "INT";
}

Regards,
Jayakumar Selvakani

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkat0454 on: 7/15/2013 [Member] Starter | Points: 25

Up
0
Down
thanks Ssj_Kumar

string Value = txtName.Text;

int num;
decimal dec;
if (int.TryParse(Value, out num ))
{
Label1.Text = "int";
}
else if (Decimal.TryParse(Value, out dec))
{
Label1.Text = "decimal";
}
else
{
Label1.Text = "string";
}


Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response