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

List generic collection 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 declare a list of integers.

C Sharp (C#)
List<int> numbers = new List<[1]>();
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cdouble
Dbool
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.
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'
AInsert
BAppend
CPush
DAdd
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.
3fill in blank
hard

Fix 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'
A-1
B1
C0
Dnumbers.Count
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.
4fill in blank
hard

Fill 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'
Astring
Bint
Cdouble
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types in the declaration and instantiation.
Using numeric types instead of string.
5fill in blank
hard

Fill 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'
Aint
Bstring
CAdd
DRemove
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove instead of Add to add elements.
Using string as the generic type when adding integers.