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

HashSet for unique elements 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 create a HashSet of integers.

C Sharp (C#)
HashSet<int> numbers = new [1]<int>();
Drag options to blanks, or click blank then click option'
AHashSet
BList
CDictionary
DQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using List instead of HashSet, which allows duplicates.
Using Dictionary which requires key-value pairs.
2fill in blank
medium

Complete the code to add an element to the HashSet.

C Sharp (C#)
numbers.[1](5);
Drag options to blanks, or click blank then click option'
APush
BAppend
CAdd
DInsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using Insert which is not a method of HashSet.
Using Push or Append which are not valid methods here.
3fill in blank
hard

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

C Sharp (C#)
bool exists = numbers.[1](10);
Drag options to blanks, or click blank then click option'
AContains
BExists
CIncludes
DHas
Attempts:
3 left
💡 Hint
Common Mistakes
Using Has or Includes which are not valid in C# HashSet.
Using Exists which is a LINQ method, not a HashSet method.
4fill in blank
hard

Fill both blanks to create a HashSet from an array and check if it contains 3.

C Sharp (C#)
int[] arr = {1, 2, 3, 4};
HashSet<int> set = new [1](arr);
bool hasThree = set.[2](3);
Drag options to blanks, or click blank then click option'
AHashSet
BContains
CList
DAdd
Attempts:
3 left
💡 Hint
Common Mistakes
Using List instead of HashSet for unique elements.
Using Add instead of Contains to check membership.
5fill in blank
hard

Fill all three blanks to add elements and check the count of unique items.

C Sharp (C#)
HashSet<string> fruits = new [1]();
fruits.[2]("apple");
fruits.[3]("banana");
int count = fruits.Count;
Drag options to blanks, or click blank then click option'
AHashSet
BAdd
DInsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using Insert which is not a method of HashSet.
Confusing Add with other collection methods.