Logo

Programming-Idioms

History of Idiom 118 > diff from v62 to v63

Edit summary for version 63 by programming-idioms.org:
[C#] Removed extra newlines

Version 62

2021-10-02, 11:10:51

Version 63

2021-10-02, 11:13:08

Idiom #118 List to set

Create set y from 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}

Idiom #118 List to set

Create set y from 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}
Variables
y,x
Variables
y,x
Imports
using System.Collections.Generic;
Imports
using System.Collections.Generic;
Code
var y = new HashSet<T>(x);

Code
var y = new HashSet<T>(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.
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__
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__
Demo URL
https://sharplab.io/#gist:375011d804fdc3d76cf53518a37309cc
Demo URL
https://sharplab.io/#gist:375011d804fdc3d76cf53518a37309cc