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

Parsing input to numeric types 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 parse the input string to an integer.

C Sharp (C#)
string input = Console.ReadLine();
int number = int.Parse([1]);
Drag options to blanks, or click blank then click option'
Anumber
BConsole.ReadLine()
Cinput
DConvert.ToInt32(input)
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console.ReadLine() directly inside int.Parse again causes double reading.
Trying to parse the variable number before it is assigned.
2fill in blank
medium

Complete the code to safely parse the input string to an integer using TryParse.

C Sharp (C#)
string input = Console.ReadLine();
if (int.TryParse([1], out int result))
{
    Console.WriteLine($"Parsed number: {result}");
}
Drag options to blanks, or click blank then click option'
Ainput
Bnumber
CConsole.ReadLine()
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the output variable result instead of the input string.
Calling Console.ReadLine() again inside TryParse.
3fill in blank
hard

Fix the error in the code to parse a double from input.

C Sharp (C#)
string input = Console.ReadLine();
double value = double.Parse([1]);
Drag options to blanks, or click blank then click option'
Avalue
Binput
CConsole.ReadLine()
Ddouble.TryParse(input, out value)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable value before assignment.
Trying to use double.TryParse inside Parse.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

C Sharp (C#)
string[] words = { "apple", "cat", "banana", "dog" };
var lengths = new Dictionary<string, int> { { [1], [2] } };
Drag options to blanks, or click blank then click option'
A"apple"
B"cat"
C5
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys or strings as values incorrectly.
Mixing up the order of key and value.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension with condition on word length.

C Sharp (C#)
string[] words = { "apple", "cat", "banana", "dog" };
var lengths = words.Where(w => w.Length > [1])
    .ToDictionary([2] => [3]);
Drag options to blanks, or click blank then click option'
A2
Bw
Cw.Length
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong number in the condition.
Swapping key and value in the dictionary.