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

How do I initialize a variable to be return from being called on with the Console.ReadLine(); method?

I tried to initialize my variable to return from being called by the Console.ReadLine(); method but when I tried to do so.... It kept giving me compiler errors.

CodeChallenge.cs
string = firstName
firstName = "Console.ReadLine()"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I feel like there is some misunderstanding of the instructions somewhere. I'll show you the line of code you need for step 1 and then explain it.

string firstName = Console.ReadLine();

Here we declare a variable named firstName and make it of type string. We initialize the variable by calling the Console.ReadLine() method which then reads a line from the console. This in itself returns a string that was read in from the console where the user typed. Whatever the user typed will now be assigned as the value of firstName.

Hope this helps! :sparkles:

Thanks