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

AYMAN ABOUZED
AYMAN ABOUZED
1,924 Points

string bookTitle = System.Console.ReadLine(); string bookTitle ="Favoritebook"; System.Console.Write("Enter a book tit

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

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

2 Answers

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

Hi there! Your code seems to be a bit out of order, but I'm guessing that's because you've fiddled with it a good bit. It seems you got the first two/three steps correct, but in the last step you're actually redeclaring your variable (as denoted by the string in front). This is not needed. Take a look at my solution:

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

The last step will read in the string entered by the user from the console and assign it back into bookTitle. Hope this helps! :sparkles:

Hi Jennifer i have a question about your answer. Why declare the variable on the first row? Iยดm a beginner but as i see it one could omit the first step and do:

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

string bookTitle = System.Console.ReadLine();

Or am i missing something?

I guess if one wants to use bookTitle multiple times?

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

Jimmy Widlund you absolutely can do that! But take a look at the challenge :smiley: I did it this way because it more accurately reflects the order of the steps in the challenge. That's all! :sparkles:

Haha ok sorry, i just jumped right in! I hope iยดll get to the challenge soon.