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 Variables

Delaine Teddy R Ndau
Delaine Teddy R Ndau
3,437 Points

how do i declare a string variable for example bookTitle

am a little lost i need to declare a string variable

CodeChallenge.cs
String bookTitle = System.Console.ReadLine ();

3 Answers

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

Giving a message to the screen

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

Taking the input from the user, putting it in variable called bookTitle

string bookTitle = System.Console.ReadLine();

Hi,

To declare a string you just give the variable type 'string' and the name of it.

string bookTitle;

You then just assign the variable a value.

string bookTitle = "Harry Potter";

Note

Your actually not entirely wrong using uppercase 'S' but there are some very slight differences between "String" and "string".

this small article does a good job at explaining it

Good luck!

Delaine Teddy R Ndau
Delaine Teddy R Ndau
3,437 Points

okay thank you and what if i want to Use the System.Console.Write() method to print "Enter a book title: " to the console.

System.Console.Write(); is a method that in your case takes a String as a parameter.

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

System.Console.Readline() is another method that takes the next line of characters from an input so it does not need any parameters.

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