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

Console.ReadLine for input in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a line of input from the user.

C Sharp (C#)
string userInput = Console.[1]();
Drag options to blanks, or click blank then click option'
AWriteLine
BReadKey
CWrite
DReadLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console.WriteLine instead of Console.ReadLine.
Using Console.ReadKey which reads only one key.
2fill in blank
medium

Complete the code to prompt the user and read their input.

C Sharp (C#)
Console.Write("Enter your name: ");
string name = Console.[1]();
Drag options to blanks, or click blank then click option'
AReadLine
BWrite
CRead
DWriteLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console.Write instead of Console.ReadLine to get input.
Using Console.Read which reads a single character.
3fill in blank
hard

Fix the error in the code to correctly read user input as a string.

C Sharp (C#)
string input = Console.[1];
Drag options to blanks, or click blank then click option'
ARead()
BReadLine()
CReadLine
DReadKey()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses after ReadLine.
Using ReadLine without parentheses which causes a compile error.
4fill in blank
hard

Fill both blanks to read an integer input from the user.

C Sharp (C#)
Console.Write("Enter a number: ");
int number = int.[1](Console.[2]());
Drag options to blanks, or click blank then click option'
AParse
BReadLine
CRead
DTryParse
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console.Read instead of Console.ReadLine.
Using int.TryParse without proper syntax.
5fill in blank
hard

Fill all three blanks to safely read an integer input using TryParse.

C Sharp (C#)
Console.Write("Enter your age: ");
string input = Console.[1]();
if (int.[2](input, out int [3]))
{
    Console.WriteLine($"Your age is {age}");
}
else
{
    Console.WriteLine("Invalid input.");
}
Drag options to blanks, or click blank then click option'
AReadLine
BTryParse
Cage
DParse
Attempts:
3 left
💡 Hint
Common Mistakes
Using int.Parse which throws error on invalid input.
Not declaring the out variable correctly.