C# SortedSet IntersectWith

Description

SortedSet IntersectWith modifies the current SortedSet object so that it contains only elements that are also in a specified collection.

Syntax

SortedSet.IntersectWith has the following syntax.


public virtual void IntersectWith(
  IEnumerable<T> other
)

Parameters

SortedSet.IntersectWith has the following parameters.

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

Example


using System;//  w  w  w.j  a v  a 2s  .c  o  m
using System.Collections;
using System.Collections.Generic;
using System.IO;


class Program
{
    static void Main(string[] args)
    {
        SortedSet<string> set1 = new SortedSet<string>();
        set1.Add("a");
        set1.Add("b");
        set1.Add("d");
        set1.Add("d");
        
        SortedSet<string> set2 = new SortedSet<string>();
        set2.Add("a");
        set2.Add("b");
        set2.Add("c");
        set2.Add("d");
        
        set1.IntersectWith(set2);

        foreach (string s in set1)
        {
            Console.WriteLine(s);
        }


    }
}

The code above generates the following result.





















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack