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
<PackageReference Include="Soenneker.Extensions.Collection" Version="4.0.1439" />
<PackageVersion Include="Soenneker.Extensions.Collection" Version="4.0.1439" />
<PackageReference Include="Soenneker.Extensions.Collection" />
paket add Soenneker.Extensions.Collection --version 4.0.1439
#r "nuget: Soenneker.Extensions.Collection, 4.0.1439"
#:package Soenneker.Extensions.Collection@4.0.1439
#addin nuget:?package=Soenneker.Extensions.Collection&version=4.0.1439
#tool nuget:?package=Soenneker.Extensions.Collection&version=4.0.1439
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 forList<T>,HashSet<T>, and otherICollection<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 | Versions 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. |
-
net10.0
- Soenneker.Extensions.List (>= 4.0.987)
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 |
Update dependency Soenneker.Extensions.List to 4.0.987 (#1793)