Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Console I/O Console I/O

MIGUEL PIETER
PLUS
MIGUEL PIETER
Courses Plus Student 756 Points

Assign bookTitle the title of your favorite book

On C# Basics there is: Assign bookTitle the title of your favorite book. How is this done. I'm stocked. What do I do?

1 Answer

cm21
cm21
150,854 Points

Hi Miguel,

1) Declaring the variable (named bookTitle, of type string... and using a semicolon to tell the compiler that the statement is over):

string bookTitle;

2) Assigning bookTitle to the title of your favorite book (using the equals sign to specify that a value is to be stored, and putting the string value in double quotes because it is string data):

string bookTitle = "That Book I Like A Lot";

3) Using the System.Console.Write() method to print a specified prompt string (message) to console:

string bookTitle = "That Book I Like A Lot";

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

4) Storing the user's response back to the bookTitle variable (using the ReadLine() method to get the next line, which is the user's response to the prompt):

string bookTitle = "That Book I Like A Lot";

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

bookTitle = System.Console.ReadLine();

Hope this helps!

string bookTitle = "That Book I Like A Lot";

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

string bookTitle = System.Console.ReadLine();