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.

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

1 Answer

Gyorgy Andorka
Gyorgy Andorka
13,809 Points


  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)