# my C# calculator can't add



## Braveheart (May 26, 2009)

```
int i1 = 10;
            int i2 = 5;
            Console.Write("and the number is: " + i1 + i2);
            Console.Read();
```

and when i run it it gives me "105" what other way is there to do this? im guessing it includes using the _math_ class?


----------



## Disparia (May 26, 2009)

My guess is that your in-line concatenation and addition is confusing it. Maybe,

Console.Write("and the number is: " + (i1 + i2));

Or the Concat function.


----------



## Kreij (May 26, 2009)

or you can use "(i1 + i2).ToString()", but I do beleive it automagically converts that to a string when it concatenates it for output to the Console.Write.


----------



## human_error (May 26, 2009)

Just create a new int i3 = i1+i2; then just print i3 out.

Your problem is that by putting it into the write function you're asking it to be treated as a string, so it's working as "i1.toString + i2.toString" instead of treating them as ints.


----------



## FordGT90Concept (May 26, 2009)

Jizzler said:


> My guess is that your in-line concatenation and addition is confusing it. Maybe,
> 
> Console.Write("and the number is: " + (i1 + i2));
> 
> Or the Concat function.


This.

string + anything = string concat anything.ToString()
number + number = number

The parenthesis forces number + number before the string + anything takes over.


----------

