[Solved] How Can i transfer the void to textbox? c#


If you want to assign something calculated in a method, then that method needs a return type. It should not be void.

public string compute1(double n1, double n2, string opr)
{
   var ans = "";
   if (opr == "-")
   {
      ans = (n1 - n2).ToString();
   }
   return ans; 
}

private void cmbOperator_SelectedIndexChanged(object sender, EventArgs e)
{
   double var1 = Convert.ToDouble(txtFirstOperand.Text);
   double var2 = Convert.ToDouble(txtSecondOperand.Text);

   if (cmbOperator.Text == "+" || cmbOperator.Text == "-")
   {
      txtResult.Text = compute1(var1, var2, opr1); //Heres the Error i want to show the answer in the box
   }
}

To assign it to the Text value of a Textbox I would suggest you return it as a string. You can also return it as a double if you want, in that case remove ToString() from the code above and set the return value as double.

0

solved How Can i transfer the void to textbox? c#