I'm trying make a program where you call operations like addition from classes.
I don't know why there's an error:
public string Add() {
string AdditionTotal;
int num1 = int.Parse(txtFirstNumber.Text);
int num2 = int.Parse(txtSecondNumber.Text);
AdditionTotal = num1 + num2; //throws an error here
return AdditionTotal;
}
public string SetText {
get {
return txtFirstNumber.Text;
}
set {
txtFirstNumber.Text = value;
}
}
Try like this
AdditionTotal = (num1 + num2).ToString();
num1 and num2 both is an int and their sum is also an int
C# can't convert it directly from int to string .
you have to cast it pragmatically in order to assign.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With