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!

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

I can't figure out why my code i'snt working?

I tried to write the code and the code doesn't working. what should I do?

System.Console.Write("Enter a book title: ");
string booktitle = System.Console.Readline("booktitle");

2 Answers

Calin Bogdan
Calin Bogdan
14,921 Points


You mistyped the function name. It's ReadLine, not Readline. Furthermore, ReadLine() doesn't take any argument. There's no need for an argument since you give the bookTitle variable the value ReadLine() returns.

Also, make sure the variable name is camelCased: bookTitle, not booktitle.

Hope it helped!

K Cleveland
K Cleveland
21,839 Points

Additionally, it's really helpful to start looking at compiler errors. You can do this by clicking on the "Preview" tab. I pretty much do this before I try to submit. If you Preview the code you wrote, you'll see an error like:

System.Console does not contain a definition for Readline

This indicates that you're not using a method that System.Console has. When I see this error, I usually start looking to see if I've misspelled something or have a typo. And as stated below, the method name is ReadLine, not Readline.

If I change your code to look like this:

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

with the proper ReadLine() method, I'll get a different error that says:

No overload for method ReadLine takes 1 arguments

This is the second part that Calin mentioned: ReadLine() doesn't take any arguments! So you now know that ReadLine("booktitle"); isn't appropriate.

A huge part of programming is getting comfortable reading these errors. It's incredibly useful because you'll be able to easily find out why your code doesn't compile, and you wont have to wait on people to answer questions you can definitely attack on your own.

Good luck!

Calin Bogdan
Calin Bogdan
14,921 Points

Changed your comment to an answer since it's far more helpful than just pointing out the issue.