Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C#

Idiom #118 List to set

Create the set y from the list x.
x may contain duplicates. y is unordered and has no repeated values.

Turning the list [a,b,c,b] into the set {c,a,b}
using System.Collections.Generic;
var y = new HashSet<T>(x);

Relies on the default equality comparer for the set type. Can be used for any type that implements such an equality comparer.
(def y (set x))

New implementation...
< >
programming-idioms.org