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 trialRaju Mandapati
123 Pointsuse System.console.ReadLine()
Can some one guide where exactly to initialze as i am failing with this many times.
System.Console.Write ("Enter a book Title: ");
System.Console.ReadLine ();
string bookTitle= "bookTitle";
2 Answers
Calin Bogdan
14,921 PointsConsole.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();
Raju Mandapati
123 PointsThank you it helps Calin.
Idowu Akinde
5,658 PointsIdowu Akinde
5,658 PointsCorrect 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();