Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a list of integers.
C Sharp (C#)
List<int> numbers = new List<[1]>(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type other than int when the list is meant for integers.
Forgetting to specify the generic type parameter.
✗ Incorrect
The generic type parameter for the list should be int to create a list of integers.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Append which is not a method of List in C#.Using
Push which is used in stacks, not lists.✗ Incorrect
The Add method is used to add an element to the end of a List in C#.
3fill in blank
hardFix the error in accessing the first element of the list.
C Sharp (C#)
int first = numbers[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the index to get the first element.
Using -1 which is invalid index in C# lists.
✗ Incorrect
List indexing in C# starts at 0, so the first element is at index 0.
4fill in blank
hardFill both blanks to create a list of strings and add a value.
C Sharp (C#)
List<[1]> names = new List<[2]>(); names.Add("Alice");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types in the declaration and instantiation.
Using numeric types instead of string.
✗ Incorrect
To create a list of strings, the generic type parameter must be string in both places.
5fill in blank
hardFill all three blanks to create a list, add an element, and get the count.
C Sharp (C#)
List<[1]> items = new List<[2]>(); items.[3](10); int count = items.Count;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Remove instead of Add to add elements.Using
string as the generic type when adding integers.✗ Incorrect
The list is of integers, so the generic type is int. To add an element, use the Add method.