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

Matthias Smartt
Matthias Smartt
186 Points

....why

don't get this at all.

CodeChallenge.cs
firstName 

What part of the code challenge are you stuck on? Part 1?

1 Answer

Hey Matthias!

The challenge (Part One of Formatting Output) requires you to

Declare a variable named firstName and initialize it to the string returned from a call to Console.ReadLine().

Let's break it down step-by-step:

  1. You want to declare a variable of type string. To do this, you need to use the word "string" in front of the variable name, like so:
string firstName; 

(Don't forget the semi-colon! C# needs these to understand where the line ends.)

  1. You then want to assign it the value returned from the "Console.ReadLine()" method. To do this, simply assign (the equals operator, =) the value (the input received from the ReadLine() method) to the string variable you declared earlier (string firstName;). That's done like so:
string firstName = Console.ReadLine();

Hopefully this helps. :-)