Get certain object from HashSet

Hi

I have HashSet filled with lets say 3 objects. How do I get lets say 2nd object out of it?

public HashSet<GameObject> myObject= new HashSet<GameObject>();

void Start()
{
    print(myObject[1].name);   //Ofcourse isn`t working
}

Any ideas please? Not much of Unity explanations on internet of using it.

HashSet is just a group of objects (in your case GameObject) and has no explicit order of elements. Therefore, you can’t get the “second” element, because no element is considered to be in a well defined position. HashSet is useful when you want to check if a value is one of a group of possible values, for example, or efficiently find out which elements are common to two different HashSets. See here for more.

In your case, where you require order, you should use a 2 instead of a HashSet. Then, you can access items by their index as you’re trying to do. I hope this helps.