ValueCollections 3.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ValueCollections --version 3.0.0
NuGet\Install-Package ValueCollections -Version 3.0.0
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="ValueCollections" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ValueCollections" Version="3.0.0" />
<PackageReference Include="ValueCollections" />
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 ValueCollections --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ValueCollections, 3.0.0"
#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 ValueCollections@3.0.0
#: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=ValueCollections&version=3.0.0
#tool nuget:?package=ValueCollections&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ValueCollections
A set of collections in C# implemented as ref struct to minimize heap allocations.
ValueList
An implementation of IList<T> using spans and array pools.
using ValueList<int> numbers = [];
for (int n = 0; n < 10; n++) {
numbers.Add(n);
}
using ValueList<int> evenNumbers = numbers.Where(number => number % 2 == 0);
Console.WriteLine(string.Join(", ", evenNumbers.ToList())); // 0, 2, 4, 6, 8
ValueHashSet
An implementation of ISet<T> using spans and array pools.
using ValueHashSet<int> numbers = [];
for (int n = 1; n <= 5; n++) {
numbers.Add(n);
}
for (int n = 3; n <= 7; n++) {
numbers.Add(n);
}
Console.WriteLine(string.Join(", ", numbers.ToArray())); // 1, 2, 3, 4, 5, 6, 7
Benchmarks
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| SmallListOfStruct | 16.85 ns | 0.122 ns | 0.108 ns | 0.0255 | 80 B |
| SmallValueListOfStruct | 14.72 ns | 0.072 ns | 0.064 ns | - | - |
| SmallListOfClass | 24.52 ns | 0.152 ns | 0.135 ns | 0.0306 | 96 B |
| SmallValueListOfClass | 18.70 ns | 0.070 ns | 0.062 ns | - | - |
| LargeListOfStruct | 20,468.89 ns | 83.070 ns | 77.704 ns | 41.6565 | 131400 B |
| LargeValueListOfStruct | 9,432.68 ns | 33.047 ns | 27.596 ns | - | - |
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|
| SmallHashSetOfStruct | 94.20 ns | 0.662 ns | 0.620 ns | 0.1070 | - | - | 336 B |
| SmallValueHashSetOfStruct | 137.42 ns | 0.616 ns | 0.577 ns | - | - | - | - |
| SmallHashSetOfClass | 130.56 ns | 0.762 ns | 0.675 ns | 0.1173 | - | - | 368 B |
| SmallValueListOfClass | 163.45 ns | 0.554 ns | 0.518 ns | - | - | - | - |
| LargeHashSetOfStruct | 186,989.50 ns | 1,425.253 ns | 1,263.450 ns | 95.2148 | 95.2148 | 95.2148 | 538656 B |
| LargeValueHashSetOfStruct | 227,245.29 ns | 603.642 ns | 564.647 ns | - | - | - | - |
Gotchas
Value collections should be disposed after use, otherwise the internal rented array will not be returned to the pool.
using ValueList<string> strings = ["a", "b", "c"];
using ValueList<string> whitespaceStrings = strings.Where(string.IsNullOrWhiteSpace);
using ValueList<string> shortWhitespaceStrings = whitespaceStrings.Where(str => str.Length <= 10);
Special Thanks
- linkdotnet/StringBuilder for inspiration.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
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 |
|---|---|---|
| 5.5.0 | 173 | 12/7/2025 |
| 5.4.0 | 193 | 11/14/2025 |
| 5.3.0 | 330 | 6/12/2025 |
| 5.2.0 | 177 | 5/29/2025 |
| 5.1.0 | 154 | 5/22/2025 |
| 5.0.0 | 180 | 5/22/2025 |
| 4.2.0 | 168 | 5/8/2025 |
| 4.1.0 | 177 | 5/8/2025 |
| 4.0.0 | 190 | 5/8/2025 |
| 3.2.0 | 172 | 4/1/2025 |
| 3.1.0 | 185 | 3/31/2025 |
| 3.0.0 | 185 | 3/31/2025 |
| 2.1.0 | 476 | 3/26/2025 |
| 2.0.0 | 312 | 3/24/2025 |
| 1.3.0 | 292 | 3/23/2025 |
| 1.2.0 | 306 | 3/23/2025 |
| 1.1.0 | 271 | 3/23/2025 |
| 1.0.0 | 286 | 3/23/2025 |