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#

Angus Eliott
Angus Eliott
3,793 Points

C# problem

could somone help me with this one? System.Console.Write("Enter a book title: "); string bookTitle; System.Console.ReadLine(bookTitle); error: Bummer! Did you set or initialize 'bookTitle' to the result from calling 'System.Console.ReadLine()'?

2 Answers

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

Hi Angus,

bookTitle needs to be assigned to the value returned from Console.ReadLine()

string bookTitle = System.Console.ReadLine();

Be sure to use the Get Help button on challenges to link your question to what you are working on, otherwise no one can follow what you are working on.

Hello!

Dale Severude's answer is correct, but I'd like to add something to it. You can simplify your code so that everything can be put into one line, like this:

// declaration
string bookTitle;

// prompt
System.Console.Write("Enter a book title: ");

// assignment
bookTitle = System.Console.ReadLine();

----------------

// We can merge the declaration and assignment, therefore it will be:
System.Console.Write("Enter a book title: ");
string bookTitle = System.Console.ReadLine();

// But System.Console.ReadLine() can take a string parameter which does the exact same thing as System.Console.Write(), so we can merge that too:

string bookTitle = System.Console.ReadLine("Enter a book title: ");

Looks cleaner, doesn't it? Good luck and keep coding!