Intersect with another collection

IntersectsWith keep only elements that are present in that object and in the specified collection.

We keep all the vowels from our set of characters in the following code:

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Sample
{
    public static void Main()
    {
        var letters = new HashSet<char>("the quick brown fox");
        letters.IntersectWith("aeiou");
        foreach (char c in letters)
            Console.Write(c);
    }

}

The output:


euio
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.