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 Converting Strings to Integers

Adding 10 to height and store it into height?

I believe i 'm doing the right thing but it won't let me pass.

Hey Brendan, This's my code: string heightInput = "168"; int heightInput = int.Parse("168"); heightInput = heightInput + 168;

you can type just like , height = height + 10; or you can type like this : height += 10;

2 Answers

Please note: I'm not currently taking this course, however I do have experience with C#.

My response may not be reflective of what has been taught to you thus far, so if someone taking this course has a more appropriate answer, please post it.

My approach would be to use the "+=" operator to add 10 to the current value of the height variable.

height += 10;

or you could also do the following

height = height + 10;

I believe both will work. Thank you.

Hi Borislav,

You cannot use "heightinput" to store the parsed value of "168". You will need to declare another variable to store the resulting parsed value. The reason for this is because your "heightinput" variable was already declared as a type "string" (you cannot have two variables with the same name).

For example, you could do the following:

string heightInput  = "168";
int height = int.Parse(heightInput);

Assuming no exceptions are thrown during the parsing of "heightInput", the "height" integer variable should be set to 168. You can then use the height variable as you please.

Hope this helps.

-- Ryan

Thank you Ryan. What you've provided It's working. The next part of the questions is to: "add 10 to height and store result back into height.