C# HashSet ExceptWith

Description

HashSet ExceptWith removes all elements in the specified collection from the current HashSet object.

Syntax

HashSet.ExceptWith has the following syntax.


public void ExceptWith(
  IEnumerable<T> other
)

Parameters

HashSet.ExceptWith has the following parameters.

  • other - The collection of items to remove from the HashSet object.

Example

Removes all elements in the specified collection from the current HashSet object.


using System;// ww w . ja  v  a 2  s  .  c o  m
using System.Collections.Generic;

public class MainClass
{
    public static void Main(String[] argv)
    {
        HashSet<int> lowNumbers = new HashSet<int>();
        HashSet<int> highNumbers = new HashSet<int>();

        for (int i = 0; i < 6; i++)
        {
            lowNumbers.Add(i);
        }

        for (int i = 3; i < 10; i++)
        {
            highNumbers.Add(i);
        }

        highNumbers.ExceptWith(lowNumbers);

    }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack