Tedd.HashSetExtensions 1.0.2

.NET Core 2.0 .NET Standard 2.0 .NET Framework 4.6.1
Install-Package Tedd.HashSetExtensions -Version 1.0.2
dotnet add package Tedd.HashSetExtensions --version 1.0.2
<PackageReference Include="Tedd.HashSetExtensions" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.HashSetExtensions --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tedd.HashSetExtensions, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tedd.HashSetExtensions as a Cake Addin
#addin nuget:?package=Tedd.HashSetExtensions&version=1.0.2

// Install Tedd.HashSetExtensions as a Cake Tool
#tool nuget:?package=Tedd.HashSetExtensions&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Tedd.HashSetExtensions

.Net extension methods for ToHashSet<T>().<br /> All methods implemented with and without both selector and comparer. Special handling of Array and List to avoid enumeration overhead. In line with how ToDictionary is implemented in .Net source code.

Examples

All methods supports selector. A selector is used to pick or transform the object before it is added to the hash.

Selector example

var dic = new Dictionary<string, int>();
dic.Add("A", 1);
dic.Add("B", 2);

// A dictionary consists of KeyValuePair and we pick the Key portion of that for our HashSet
var hashSet = dic.ToHashSet(s => s.Key);

dic.Add("CC", 2);
// Or we can have more complex logic
var hashSet2 = dic.ToHashSet(s => {
	if (s.Key == "CC")
		return "C";
	return s.Key;
});

Methods

ienumerable.ToHashSet()

var list = new List<string>();
list.Add("A");
list.Add("B");
var hashSet = list.ToHashSet(); // No selector needed
var thisIsTrue = hashSet.Contains("A");
var thisIsFalse = hashSet.Contains("C");

// Add B again
list.Add("B");
var hashSet2 = list.ToHashSet(s => s); // Using selector
// HashSet only cointains 2 items because duplicates are ignored
var thisIsTwo = hashSet2.Count;

ienumerable.ToHashSet(selector, comparer)

var list = new List<string>();
list.Add("a");
list.Add("b");
var hashSet = list.ToHashSet(s => s, StringComparer.InvariantCultureIgnoreCase);
// HashSet now contains: a, b

var thisIsTrue = hashSet.Contains("a");
var thisIsAlsoTrue = hashSet.Contains("A");

hashset.ContainsRange(ienumerable)

var list = new List<string>();
list.Add("A");
list.Add("B");
list.Add("C");
var hashSet = list.ToHashSet(s => s);
// HashSet now contains: A, B, C

var otherList = new List<string>();
otherList.Add("A");
otherList.Add("B");

var thisIsTrue = hashSet.ContainsRange(otherList);

hashset.AddRange(ienumerable)

var list1 = new List<string>();
list1.Add("A");
list1.Add("B");
var hashSet = list1.ToHashSet(s => s);
// HashSet now contains: A, B

var list2 = new List<string>();
list.Add("C");
list.Add("D");
hashSet.AddRange(list2);
// HashSet now contains: A, B, C, D

var thisIsTrue = hashSet.Contains("D");

hashset.RemoveRange(ienumerable)

var list1 = new List<string>();
list1.Add("A");
list1.Add("B");
list1.Add("C");
list1.Add("D");
var hashSet = list1.ToHashSet();
// HashSet now contains: A, B, C, D

var list2 = new List<string>();
list.Add("A");
list.Add("B");
hashSet.RemoveRange(list2);
// HashSet now contains: B, C


var thisIsFalse = hashSet.Contains("A");
var thisIsAlsoFalse = hashSet.Contains("B");
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.0

    • No dependencies.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tedd.HashSetExtensions:

Package Downloads
Tedd.DictionaryUtils

Extensions to Dictionary<TKey, TValue>

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 445 2/15/2020
1.0.1 318 2/14/2020
1.0.0 263 2/14/2020

Contains for array, list and ienumerable