Logo

Programming-Idioms

History of Idiom 118 > diff from v35 to v36

Edit summary for version 36 by aolszowka:
New Csharp implementation by user [aolszowka]

Version 35

2019-06-28, 10:39:54

Version 36

2019-09-26, 15:21:04

Idiom #118 List to set

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

Illustration

Idiom #118 List to set

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

Illustration
Imports
using System.Collections.Generic;
Code
static void Main(string[] args)
{
    string[] x = new string[] { "a", "b", "c", "b" };
    HashSet<string> y = new HashSet<string>(x);
}
Comments bubble
Relies on the default equality comparer for the set type. Can be used for any type that implements such an equality comparer.
Doc URL
https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.-ctor?view=netframework-4.8#System_Collections_Generic_HashSet_1__ctor_System_Collections_Generic_IEnumerable__0__