0
0
C Sharp (C#)programming~5 mins

Console.ReadLine for input in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Console.ReadLine() do in C#?

Console.ReadLine() waits for the user to type some text and press Enter. It then returns that text as a string.

Click to reveal answer
beginner
How do you store user input from Console.ReadLine()?

You assign the result of Console.ReadLine() to a string variable, like string name = Console.ReadLine();.

Click to reveal answer
beginner
What type of data does Console.ReadLine() return?

It returns a string, which is text data.

Click to reveal answer
intermediate
How can you convert the input from Console.ReadLine() to a number?

You can use methods like int.Parse() or int.TryParse() to change the string input into an integer.

Click to reveal answer
beginner
Why is Console.ReadLine() useful in console applications?

It lets the program get information typed by the user, making the program interactive.

Click to reveal answer
What does Console.ReadLine() return?
AA string typed by the user
BAn integer number
CA boolean value
DNothing, it just waits
How do you save the input from Console.ReadLine()?
ACall <code>Console.Read()</code>
BAssign it to a string variable
CUse <code>Console.WriteLine()</code>
DAssign it to an integer variable directly
Which method converts a string input to an integer?
Astring.ToInt()
BConsole.ReadLine()
Cint.Parse()
DConsole.WriteLine()
What happens if you press Enter without typing anything when Console.ReadLine() runs?
AIt returns an empty string
BIt returns null
CIt throws an error
DIt waits forever
Why might you use int.TryParse() instead of int.Parse() after Console.ReadLine()?
ATo read input faster
BTo print the input
CTo convert input to a string
DTo safely check if input is a number without crashing
Explain how Console.ReadLine() works and how you can use it to get user input in a C# program.
Think about how you ask a friend to tell you something and you write it down.
You got /4 concepts.
    Describe how to convert the string from Console.ReadLine() into a number and why this might be necessary.
    Imagine you ask someone their age and get it as words, but you need it as a number.
    You got /4 concepts.