Set operation: Except
In this chapter you will learn:
Set operation Except
ExceptWith removes the specified elements from the source set. Here, we strip all vowels from the set:
using System;/*from j a va2 s . c o m*/
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.ExceptWith("aeiou");
foreach (char c in letters)
Console.Write(c);
}
}
The output:
SymmetricExceptWith
SymmetricExceptWith removes all but the elements that are unique to one set or the other.
using System;// ja v a 2 s . c om
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.SymmetricExceptWith("the lazy brown fox");
foreach (char c in letters)
Console.Write(c);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Collections