Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize a list of integers with values 1, 2, and 3.
C Sharp (C#)
var numbers = new List<int> [1] 1, 2, 3 [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () instead of curly braces {} for collection initialization.
Using square brackets [] which are for arrays, not collections.
✗ Incorrect
In C#, collection initializers use curly braces { } to list the elements inside the new collection.
2fill in blank
mediumComplete the code to initialize a dictionary with keys "apple" and "banana" and values 1 and 2.
C Sharp (C#)
var fruitCounts = new Dictionary<string, int> [1] {"apple", 1}, {"banana", 2} [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () instead of curly braces {} for dictionary initialization.
Using square brackets [] which are not valid for dictionary initializers.
✗ Incorrect
Dictionaries use curly braces { } with key-value pairs inside for initialization.
3fill in blank
hardFix the error in the code to correctly initialize a list of strings with "red", "green", and "blue".
C Sharp (C#)
var colors = new List<string> [1] "red", "green", "blue" [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which are for arrays, not collections.
Using parentheses () which are for method calls, not initializers.
✗ Incorrect
Collection initializers require curly braces { } around the elements after the new keyword.
4fill in blank
hardFill both blanks to initialize a dictionary with keys 1 and 2 and values "one" and "two".
C Sharp (C#)
var numbers = new Dictionary<int, string> [1] {1, "one"}, {2, "two"} [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] or parentheses () instead of curly braces.
Forgetting to close the initializer with the correct brace.
✗ Incorrect
Dictionary initializers use curly braces { } to enclose the key-value pairs.
5fill in blank
hardFill the two blanks to initialize a list of tuples with (1, "one"), (2, "two"), and (3, "three").
C Sharp (C#)
var list = new List<(int, string)> [1] (1, "one"), (2, "two"), (3, "three") [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for the initializer.
✗ Incorrect
Collection initializers use curly braces { } around the elements.