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) Console I/O Formatting Output

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

Task 2 of 3

CodeChallenge.cs
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
231,236 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.