Soenneker.Extensions.Collection 4.0.1439

Prefix Reserved
dotnet add package Soenneker.Extensions.Collection --version 4.0.1439
                    
NuGet\Install-Package Soenneker.Extensions.Collection -Version 4.0.1439
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Extensions.Collection" Version="4.0.1439" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.Collection" Version="4.0.1439" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.Collection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Extensions.Collection --version 4.0.1439
                    
#r "nuget: Soenneker.Extensions.Collection, 4.0.1439"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Extensions.Collection@4.0.1439
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Extensions.Collection&version=4.0.1439
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.Collection&version=4.0.1439
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Extensions.Collection

Mutating helpers for removing matching items from ICollection<T> and conditionally adding non-null values.

Installation

dotnet add package Soenneker.Extensions.Collection

Remove multiple values

using Soenneker.Extensions.Collection;

var names = new List<string> { "Alpha", "Beta", "ALPHA", "Gamma" };

names.RemoveEnumerableFromCollection(
    ["alpha", "gamma"],
    StringComparer.OrdinalIgnoreCase);

// names contains only "Beta"

RemoveEnumerableFromCollection() mutates the target and removes every occurrence that matches any supplied removal value. Missing values are ignored. The removal sequence is materialized before the target changes, so it is safe to pass the same collection as both arguments.

Equality selection is explicit:

  • A supplied IEqualityComparer<T> is honored for List<T>, HashSet<T>, and other ICollection<T> implementations.
  • Without one, a HashSet<T> target uses its own comparer.
  • Other target types use EqualityComparer<T>.Default.

The method creates a HashSet<T> of removal values. Lists and hash sets use optimized in-place removal. Other collection types are scanned into a temporary list before removal, avoiding mutation during enumeration and ensuring duplicate matching elements are all removed.

Null or empty target/removal collections are no-ops. A read-only collection still throws from its own Remove implementation when a match is found. The method provides no locking; callers must synchronize concurrent mutation.

For a short inline list, RemoveFromCollection() is a params convenience wrapper:

names.RemoveFromCollection("Beta", "Gamma");

Add non-null values

var recipients = new List<string>();
string? optionalAddress = GetAddress();

recipients.AddIfNotNull(optionalAddress);

AddIfNotNull() skips a null reference or nullable value and otherwise calls the target collection's Add. It does not prevent duplicates, validate the value, or suppress exceptions from a read-only/fixed-size collection. Non-nullable value types are always added, including their default value.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1439 80 8/31/2026
4.0.1438 77 8/30/2026
4.0.1437 74 8/30/2026
4.0.1436 76 8/30/2026
4.0.1435 74 8/29/2026
4.0.1434 77 8/29/2026
4.0.1433 78 8/29/2026
4.0.1432 88 8/26/2026
4.0.1431 108 8/12/2026
4.0.1430 110 7/28/2026
4.0.1429 99 7/28/2026
4.0.1428 105 7/27/2026
4.0.1427 115 7/18/2026
4.0.1426 104 7/18/2026
4.0.1425 123 6/18/2026
4.0.1424 117 6/18/2026
4.0.1423 118 6/10/2026
4.0.1422 124 6/6/2026
4.0.1421 115 6/5/2026
4.0.1420 111 6/5/2026
Loading failed

Update dependency Soenneker.Extensions.List to 4.0.987 (#1793)