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

Why collections over arrays in C Sharp (C#) - Test Your Understanding

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

Complete the code to create a list of integers.

C Sharp (C#)
List<int> numbers = new List<int>[1];
Drag options to blanks, or click blank then click option'
A()
B[]
C{}
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of parentheses.
Using curly braces {} which are for collection initializers.
2fill in blank
medium

Complete the code to add an element to the list.

C Sharp (C#)
numbers.[1](5);
Drag options to blanks, or click blank then click option'
AAppend
BAdd
CInsert
DPush
Attempts:
3 left
💡 Hint
Common Mistakes
Using Append which is not a method on List.
Using Push which is used in stacks.
3fill in blank
hard

Fix the error in the code to check if the list contains the number 10.

C Sharp (C#)
bool hasTen = numbers.[1](10);
Drag options to blanks, or click blank then click option'
AHas
BIncludes
CExists
DContains
Attempts:
3 left
💡 Hint
Common Mistakes
Using Has which is not a List method.
Using Includes which is from JavaScript.
4fill in blank
hard

Fill both blanks to create a dictionary and add a key-value pair.

C Sharp (C#)
Dictionary<string, int> ages = new Dictionary<string, int>[1];
ages.[2]("Alice", 30);
Drag options to blanks, or click blank then click option'
A()
BAdd
CInsert
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} to create the dictionary without initial values.
Using Insert which is not a Dictionary method.
5fill in blank
hard

Fill all three blanks to create a list, add an element, and check its count.

C Sharp (C#)
List<string> fruits = new List<string>[1];
fruits.[2]("Apple");
int count = fruits.[3];
Drag options to blanks, or click blank then click option'
A()
BAdd
CCount
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Length which is for arrays, not lists.
Forgetting parentheses when creating the list.