Hashset

HashSet is a collection containing only unique elements.

Introduction

In order to use it, the following line needs to be added:

Syntax

Inserting Data

Insertion is done via the Add function. Like in the following example:

Output:

Notice that Tokyo is contained only once, since no duplicates are allowed.

Size

Size is the count of HashSet elements. It's accessed via the Count property.

Output:

Remove Element

Certain values can be removed via the remove function.

Output:

Contains

A value can be checked if contained via the contains method.

Output:

Loop Through

It can be iterated via for and for-each loop:

Output: