Check if HashSet and the specified collection contain the same elements in CSharp

Description

The following code shows how to check if HashSet and the specified collection contain the same elements.

Example


/*from  w  w w.j  a  va  2 s .co  m*/
using System;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    HashSet<int> lowNumbers = new HashSet<int>();
    HashSet<int> allNumbers = new HashSet<int>();

    for (int i = 1; i < 5; i++)
    {
        lowNumbers.Add(i);
    }

    for (int i = 0; i < 10; i++)
    {
        allNumbers.Add(i);
    }

    Console.WriteLine(allNumbers.SetEquals(lowNumbers));

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary