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

Add 10 to height and store result back into height.

Add 10 to height and store result back into height.

CodeChallenge.cs
string heightInput = "168";
int height = int.Parse(height);
int height = 10 + ("height");

1 Answer

Hi!

  1. You should pass the heightInput variable to the int.Parse() method, and not height, which is a non-existing reference at this point. This will convert heightInput (a string type) to an int, and that integer value can then be assigned to the height variable, which has been declared as an int type reference.

  2. On the third line, you should add 10 to the variable height and reassign this incremented value to itself (height = height + 10;). Note that you don't need to redeclare the height variable, i.e. you should not give the type (int) before the variable name again - at this point the program already knows what height refers to. (When you define the type before a variable name, like int height = ... it means redeclaration, i.e. creating a completely new reference variable, a "fresh start" for height if you like)