Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perform Integers

Autumn Fisher
PLUS
Autumn Fisher
Courses Plus Student 2,165 Points

“6” + 5 =

I understand if "5"+"5" is 25 or "6"+"6" is 36, but what if both numbers aren't in quotations? What does this equal?

2 Answers

Steven Parker
Steven Parker
231,248 Points

is a case of "type coercion".

Just to be clear: "" :point_left: these are quotes (not parentheses).

So when you combine a string with a number, the compiler does something called type coercion where it tries to make the arguments the same type. In this case, it converts the number into a string, and then it handles it the same way it would if you started with this: "6" + "5".

When you put double quotation marks around a character, you asking that the character 6 be used, instead of the value of 6. So if you run the code, as you displayed it, you should receive the character 6 concatenated to the character 5. That is, of course, if you use the var or string data type. If you use any other data type, you should receive an error.