Soenneker.Extensions.List
4.0.994
Prefix Reserved
dotnet add package Soenneker.Extensions.List --version 4.0.994
NuGet\Install-Package Soenneker.Extensions.List -Version 4.0.994
<PackageReference Include="Soenneker.Extensions.List" Version="4.0.994" />
<PackageVersion Include="Soenneker.Extensions.List" Version="4.0.994" />
<PackageReference Include="Soenneker.Extensions.List" />
paket add Soenneker.Extensions.List --version 4.0.994
#r "nuget: Soenneker.Extensions.List, 4.0.994"
#:package Soenneker.Extensions.List@4.0.994
#addin nuget:?package=Soenneker.Extensions.List&version=4.0.994
#tool nuget:?package=Soenneker.Extensions.List&version=4.0.994
Soenneker.Extensions.List
In-place replacement, removal, shuffling, random selection, and set conversion for List<T> and IList<T>.
Installation
dotnet add package Soenneker.Extensions.List
Replace or remove the first match
using Soenneker.Extensions.List;
var jobs = new List<Job> {queued, running, completed};
jobs.Replace(job => job.Id == updated.Id, updated);
jobs.Remove(job => job.Id == obsoleteId);
Replace() changes only the first match. Remove() removes only the first match and preserves the order of every remaining item. A null or empty list is a no-op. A null predicate throws only when the list contains items.
Use the state-aware RemoveAll() when every match should be removed without a closure allocation:
int removed = jobs.RemoveAll(
static (job, state) => job.Status == (JobStatus)state!,
JobStatus.Completed);
RemoveAll() compacts survivors in place, preserves their order, and returns the number removed. The list and predicate must not be mutated recursively while any of these operations are evaluating the predicate.
Shuffle in place
items.Shuffle(); // fast, non-cryptographic
items.SecureShuffle(); // cryptographic random source
Both methods use an unbiased Fisher-Yates shuffle and modify the supplied writable IList<T>. Null lists and lists with fewer than two items are unchanged. Shuffle() is appropriate for presentation order, retry spreading, and games that do not involve security. Use SecureShuffle() when the permutation must not be predictable, such as drawing prizes or security-sensitive assignments.
Neither method returns a copy. Create one first when the original order must be retained:
var shuffled = new List<Card>(deck);
shuffled.Shuffle();
Select one item
Server? server = servers.GetRandom();
GetRandom() uses the same fast, non-cryptographic source as Shuffle(). It returns default(T) for a null or empty list, so the result cannot distinguish an empty list from a list whose selected element is itself null or the value-type default.
Create a set
HashSet<string> names = values.ToHashSet(StringComparer.OrdinalIgnoreCase);
ToHashSet() returns a new set and removes duplicates according to the supplied comparer, or EqualityComparer<T>.Default when none is supplied. A null or empty list returns an empty set configured with that comparer. Later changes to the list and set are independent.
| 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.Utils.Random (>= 4.0.135)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Soenneker.Extensions.List:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.TomSelect
A Blazor interop library for the select user control library, Tom Select |
|
|
Soenneker.Blazor.FilePond
A Blazor interop library for the file upload library FilePond |
|
|
Soenneker.GitHub.Repositories.PullRequests
Retrieves, reviews, rebases, and merges GitHub pull requests across repositories |
|
|
Soenneker.Extensions.Collection
Helpful Collection extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.994 | 2,162 | 9/24/2026 |
| 4.0.993 | 108 | 9/24/2026 |
| 4.0.992 | 1,839 | 9/15/2026 |
| 4.0.991 | 286 | 9/15/2026 |
| 4.0.990 | 1,335 | 9/13/2026 |
| 4.0.989 | 831 | 9/12/2026 |
| 4.0.988 | 1,364 | 9/8/2026 |
| 4.0.987 | 4,879 | 8/31/2026 |
| 4.0.986 | 948 | 8/30/2026 |
| 4.0.985 | 397 | 8/29/2026 |
| 4.0.984 | 308 | 8/29/2026 |
| 4.0.983 | 1,449 | 8/26/2026 |
| 4.0.982 | 3,500 | 8/11/2026 |
| 4.0.981 | 4,657 | 7/28/2026 |
| 4.0.980 | 173 | 7/27/2026 |
| 4.0.979 | 4,126 | 7/16/2026 |
| 4.0.977 | 1,417 | 7/14/2026 |
| 4.0.976 | 4,673 | 6/18/2026 |
| 4.0.975 | 130 | 6/18/2026 |
| 4.0.974 | 3,187 | 6/10/2026 |
Updated NuGet packages