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

Raju Mandapati
Raju Mandapati
123 Points

use System.console.ReadLine()

Can some one guide where exactly to initialze as i am failing with this many times.

CodeChallenge.cs
System.Console.Write ("Enter a book Title: ");
System.Console.ReadLine ();
string bookTitle= "bookTitle";

2 Answers

Console.ReadLine() returns a string with the last value you entered.

Since ReadLine() returns a string with that value, you have to store the value in a variable, like so:

string bookTitle = System.Console.ReadLine();
Idowu Akinde
Idowu Akinde
5,658 Points

Correct answer, Calin Bogdan.

However Raju Mandapati, you can optimize that line of code further by replacing the "string" keyword with "var", like below:

      var bookTitle = System.Console.ReadLine();
Raju Mandapati
Raju Mandapati
123 Points

Thank you it helps Calin.