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

Matthew Tyler
Matthew Tyler
653 Points

i don't understand this c# question

So on an excersise I was asked to "Declare a variable named firstName and initialize it to the string returned from a call to Console.ReadLine()." and I've tried really hard to answer it but I just don't get it. I'm new to c# and i really don't understand. Also, I look on the previous videos and there is nothing to help me. Can somebody help me out please?

CodeChallenge.cs
using System;

string firstName = Console.ReadLine();

2 Answers

Chris Kopcow
Chris Kopcow
2,852 Points

You're right. This SHOULD work. But I think you're a little ahead of the game here, and it's messing with Treehouse.

At this point, I don't think they've really taught you about "using" yet, or at least they don't expect you to use it. So what they really want you to use is

string firstName = System.Console.ReadLine();

to access the System namespace that way rather than with "using." I tried that out, and it worked.

Hope that helps!

Changed to an answer - Dane E. Parchment Jr. (Moderator)

Steven Parker
Steven Parker
173,889 Points

Including the namespace in the call doesn't hurt but isn't necessary.

Steven Parker
Steven Parker
173,889 Points

Many challenges, like this one, do some of the work for you even though you don't see it. You can usually tell what might have been done for set-up by what the instructions ask you to do.

The code you write here already has access to the "System" namespace, so you don't need a "using" statement or to include it in the method calls. This was hinted by the instructions specifically suggesting the use of "Console.ReadLine".