C# C# Basics (Retired) Console I/O Formatting Output

Use Console.WriteLine to print the contents of the firstName variable to the screen.

Task 2 of 3

string firstName = Console.ReadLine();
Console.WriteLine ("firstName");

Try giving more context by explaining what you are trying to do, and what your code is actually doing. This helps others make more intelligent comments and feel like you are invested in this question (and not just asking them to write your code for you). This applies not only to Team Treehouse comments, but anywhere online (stackoverflow.com) you may ask a question about coding.

2 Answers

Steven Parker
Steven Parker
187,274 Points

Never put quotes around a variable name. That creates a string literal instead of referencing the variable.

What you are doing here is creating a string (a variable) named firstName in your program and setting it to whatever the user inputs. This part is correct.

The 2nd line is where you have trouble. You are not referencing the variable firstName you created on the previous line, but are instead passing in the string "firstName" instead of the variable. Basically your code will always print out "firstName", regardless of what the user types in. In order to print what the user types in, you need to use the variable firstName (without the quotes). This is the actual variable you stored the input in, not just some text in your code.