C# HashSet SymmetricExceptWith

Description

HashSet SymmetricExceptWith modifies the current HashSet object to contain only elements that are present either in that object or in the specified collection, but not both.

Syntax

HashSet.SymmetricExceptWith has the following syntax.


public void SymmetricExceptWith(
  IEnumerable<T> other
)

Parameters

HashSet.SymmetricExceptWith has the following parameters.

  • other - The collection to compare to the current HashSet object.

Example

The following example creates two HashSet collections with overlapping sets of data.


/*from  w ww. j a  va2s. c o m*/
using System;
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);
    }

    lowNumbers.SymmetricExceptWith(highNumbers);

  }
}
   




















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack