0
Hi Friend,
In previous reply, one part is missing. I think this reply will be more helpful to you.
private void button1_Click(object sender, EventArgs e)
{
string cookie = "1234.6";
int intcookie = 0;
int result;
double result2;
if (Int32.TryParse(cookie, out result))
{
intcookie = result;
}
else if (Double.TryParse(cookie, out result2))
{
intcookie = (int)result2;
}
else
{
MessageBox.Show("Cookie is not a number.");
}
}
Please mark Do you like this answer checkbox, if this helps you. 0
Hi home base......
thanks for ur reply..but it created error in int32.parse(2nd line)..the error is input string was not in a correct format
0
You can use the Convert class or the Parse method of the built-in type you are casting to. i.e.
string myStr = "123";
int myParsedInt = Int32.Parse(myStr);
int myConvertedInt = Convert.ToInt32(myStr);
This example uses the int type, but you can also use the same techniques for any of the other integral or floating point types.