Welcome to the Treehouse Community
Looking to learn something new?
How is Console.ReadLine different from a variable?
As I have understood it, Console.ReadLine stores input from the user, which then can be used fx with Console.WriteLine which then writes it out. Please correct me if I'm wrong. But how is this different from a variable?
Dominik Huber4,631 Points
Console.ReadLine doesn't actually stores the input from the user, it just returns the input from the user as a String. I don't know if you learned about Methods yet but ReadLine is a Method from the Console class.
And this method returns a string. So you need a variable to hold the value it returns, otherwise it's gone. You have to save this string either in a variable or print it out directly. 3 quick examples:
Console.ReadLine(); --> The input from the user is gone. (though often used to halt the program and continues after the user has hit enter key.
string userInput = Console.ReadLine() --> Input is stored in userInput variable
Console.WriteLine(Console.ReadLine()); --> The input is gone but it get's printed out on the console. But it can't be used later because it's not stored anywhere.