Anyone, please take a look at my line of code.
int totalValue = 0;
totalValue = int.Parse(Label9.Text) * int.Parse(Label6.Text);
Label8.Text = **totalVa
That's because totalValue
is an int
.
Try this:
Label8.Text = totalValue.ToString();
Using the text directly is not a good way, what if parsing fails?
Use
int? val1=GetInt32(Label9.Text);
int? val2=GetInt32(Label6.Text);
if(val1!=null&&val2!=null)
{
int totalValue = 0;
totalValue = val1+val2;
Label8.Text = totalValue.ToString();
}
//You can also write your own logic on the TextBoxs if they did not contain a valid value by checking if val1 or val2 are null or not
Using the function to return int value if the input can be converted.
public int? GetInt32(string s)
{
int i;
if (Int32.TryParse(s, out i)) return i;
return null;
}
try this:
int totalValue = 0;
totalValue = int.Parse(Label9.Text) * int.Parse(Label6.Text);
Label8.Text = totalValue.ToString();
You should convert int to string. Something like this:
Label8.Text = totalValue.ToString();
Or this:
Label8.Text = totalValue + "";