int I;
if(int。 TryParse (text box. Text,out i))
{
//It's plastic, and I'm used directly.
}
At the same time, there is body double. TryParse, wait.
Supplement:
Private void b 1_Click (object sender, EventArgs e)
{
Const double pi = 3.14;
Double r, l, v;
if (t 1。 Text == " ")
Label 4. Text = "cannot be empty";
else if(! Single. TryParse(t 1。 Text,out r){
Label 4. Text = "Must be a number";
}
other
{
// r = conversion. ToSingle(t 1。 Text); Is already available.
l = Pi * r * 2;
v = Pi * r * r
t2。 Text = transformation. ToString(l);
t3。 Text = transformation. ToString(v);
Label 4. Text =
}
}
Supplement 2:
TryParse tried to convert a string into a number. If successful, it sets the value of the out parameter and returns true; otherwise, out is the default value and returns false.
Parse is to forcibly convert a number string into a number, and an exception will be thrown if it is unsuccessful.
TryParse is only available after C#2.0.