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 Receiving Input

What is the : inside the () for?

what is the : inside () for ?

in this

system.console.write("enter how many minutes you exercised: ");

and also why do we need to put string when we make a variable if we make a variabel that is not string what do we put infront?

also why do we write readlane instead of just read for

system.console.write("enter how many minutes you exercised: ");

1 Answer

andren
andren
28,558 Points

what is the : inside () for? in this

system.console.write("enter how many minutes you exercised: ");

Everything within the double quotes is a string, a string is pure text, nothing within that string holds a special meaning. It is just text that gets printed to the screen. The instructor likely placed the colon at the end of the message because it makes the message look a bit cleaner, it is purely a stylistic choice, not a functional one.

and also why do we need to put string when we make a variable if we make a variabel that is not string what do we put infront?

When you declare a variable you specify the datatype that the variable will hold. string is a datatype that represents pure text. Other common datatypes include int which is used to represents whole numbers like 2, 15, 20, etc. float which is used to represent numbers with decimals places like 2.5, 16.1, 50.231, etc.

Here are examples of non-string variables:

int number1 = 20;
float number2 = 3.1563;

There are lots of other builtin datatypes, and you can also define your own through classes but that is something you will be taught more about later in the track.

also why do we write readlane instead of just read

System.Console.ReadLine is a method that gathers input until it detects a new line (which a user generates by hitting enter) and then converts it to a string. System.Console.Read only gathers a single input.

That means that if you use System.Console.Read then you would only get a single button press back from the user, not a whole word or sentence as the method would only listen for the first keypress.