Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an item to the list.
C Sharp (C#)
List<string> fruits = new List<string>(); fruits.[1]("Apple");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove instead of Add will try to delete an item.
Using Find or Sort will not add items.
✗ Incorrect
The Add method adds an item to the end of the list.
2fill in blank
mediumComplete the code to remove an item from the list.
C Sharp (C#)
List<int> numbers = new List<int> {1, 2, 3};
numbers.[1](2); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add will add an item instead of removing.
Using Find or Sort will not remove items.
✗ Incorrect
The Remove method deletes the first occurrence of the specified item from the list.
3fill in blank
hardFix the error in the code to find an item in the list.
C Sharp (C#)
List<string> names = new List<string> {"Anna", "Bob", "Cara"};
string found = names.[1](name => name == "Bob"); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add or Remove will not find items.
Using Sort will reorder the list, not find an item.
✗ Incorrect
The Find method searches for an item that matches the condition given by a lambda expression.
4fill in blank
hardFill both blanks to sort the list in ascending order and then remove the first item.
C Sharp (C#)
List<int> values = new List<int> {5, 3, 8};
values.[1]();
values.[2](values[0]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add instead of Remove will add an item instead of deleting.
Using Find instead of Sort will not order the list.
✗ Incorrect
First, Sort() arranges the list in ascending order. Then, Remove() deletes the first item.
5fill in blank
hardFill all three blanks to add a new item, find it, and then remove it from the list.
C Sharp (C#)
List<string> pets = new List<string> {"Cat", "Dog"};
pets.[1]("Bird");
string foundPet = pets.[2](p => p == "Bird");
pets.[3](foundPet); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of methods.
Using Sort instead of Find or Remove.
✗ Incorrect
We add "Bird" with Add, find it with Find, then remove it with Remove.