Complete the code to create a HashSet of integers.
HashSet<int> numbers = new [1]<int>();The HashSet class is used to store unique elements. Here, we create a new HashSet of integers.
Complete the code to add an element to the HashSet.
numbers.[1](5);
The Add method adds an element to the HashSet if it is not already present.
Fix the error in the code to check if the HashSet contains the number 10.
bool exists = numbers.[1](10);
The Contains method checks if an element exists in the HashSet.
Fill both blanks to create a HashSet from an array and check if it contains 3.
int[] arr = {1, 2, 3, 4};
HashSet<int> set = new [1](arr);
bool hasThree = set.[2](3);We create a HashSet from the array arr. Then we use Contains to check if 3 is in the set.
Fill all three blanks to add elements and check the count of unique items.
HashSet<string> fruits = new [1](); fruits.[2]("apple"); fruits.[3]("banana"); int count = fruits.Count;
We create a HashSet of strings, add "apple" and "banana" using Add, then get the count of unique items.