A HashSet variable declaration needs to meet the following requirements:
- The HashSet keyword, its element type between left and right arrow characters, and a unique name
- The new keyword to initialize the HashSet in memory, followed by the HashSet keyword and element type between arrow characters.
- A pair of parentheses capped off by a semicolon.
In blueprint form, it looks as follows:
HashSet<elementType> name = new HashSet<elementType>();
Unlike stacks and queues, you can initialize a HashSet with default values when declaring the variable:
HashSet<string> people = new HashSet<string>();
// OR
HashSet<string> people = new HashSet<string>() { "Joe", "Joan", "Hank"};
To add elements, use the Add method and specify the new element:
people.Add("Walter");
people.Add("Evelyn");
To remove an element, call Remove and specify the element you want to delete from the...