hi guys just wanted to ask how I can add numbers in string form, I tried to add them but instead of getting 9 I get 36. here's how I tried it:

            Compute comp = new Compute();
            comp.Bet = betTextbox.Text;
            comp.Funds = fundsTextbox.Text;

            betTextbox.Text = "6";
            fundsTextbox.Text = "3";

            Convert.ToInt32(betTextbox.Text);
            Convert.ToInt32(fundsTextbox.Text);

            string total = fundsTextbox.Text + betTextbox.Text;

            Convert.ToInt32(total);

            prizeTextbox.Text = total;

My plan is to add the values of betTextbox.Text and fundsTextbox.Text and get 9 as the sum. But I get 9 as a result, can anyone help me out please? thank you very much for the ones who will help out. :)

No, strings aren't int, they are different data types.
use
int total = fundsTextbox + betTextbox;
then convert the total to string

Where are you storing the converted integers?

Writing like:

int bet=Convert.ToInt32(betTextbox.Text);
int funds=Convert.ToInt32(fundsTextbox.Text);

will help.The you can add them like integers and then assign the value with a concatenation with "" to the output field.

@delta_frost I tried that but it didn't work either...

            Compute comp = new Compute();
            comp.Bet = betTextbox.Text;
            comp.Funds = fundsTextbox.Text;

           int f =  Convert.ToInt32(betTextbox.Text);
           int g = Convert.ToInt32(fundsTextbox.Text);
           int h = Convert.ToInt32(prizeTextbox.Text);

           h = f + g;

           Convert.ToString(h);

this still did not work for me. help please

Comments
merry christmas
var x = Convert.ToInt32(betTextbox.Text);
var y = Convert.ToInt32(fundsTextbox.Text);

string total = (x + y).ToString();

Edited 4 Years Ago by ArbenM

I got it figured out guys thanks to your help! This one worked for me:

            Compute comp = new Compute();
            comp.Bet = betTextbox.Text;
            comp.Funds = fundsTextbox.Text;
            int f = Convert.ToInt32(betTextbox.Text);
            int g = Convert.ToInt32(fundsTextbox.Text);
            int h;
            h = f + g;
            prizeTextbox.Text = h.ToString();
This question has already been answered. Start a new discussion instead.