ValueCollections 6.3.0
dotnet add package ValueCollections --version 6.3.0
NuGet\Install-Package ValueCollections -Version 6.3.0
<PackageReference Include="ValueCollections" Version="6.3.0" />
<PackageVersion Include="ValueCollections" Version="6.3.0" />
<PackageReference Include="ValueCollections" />
paket add ValueCollections --version 6.3.0
#r "nuget: ValueCollections, 6.3.0"
#:package ValueCollections@6.3.0
#addin nuget:?package=ValueCollections&version=6.3.0
#tool nuget:?package=ValueCollections&version=6.3.0
ValueCollections
A set of collections in C# implemented as struct to minimize heap allocations.
ValueList
An implementation of List<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 HashSet<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
ValueDictionary
An implementation of Dictionary<TKey, TValue> using spans and array pools.
using ValueDictionary<string, string> strings = [];
strings.Add("food", "pizza");
strings.Add("drink", "cola");
Console.WriteLine(string.Join(", ", strings.ToArray())); // [food, pizza], [drink, cola]
ValueStack
An implementation of Stack<T> using spans and array pools.
using ValueStack<int> numbers = new();
numbers.Push(1);
numbers.PushRange([3, 3]);
numbers.Push(7);
numbers.Pop();
Console.WriteLine(string.Join(", ", numbers.ToArray())); // 3, 3, 1
ValueList (Fixed Size)
A set of implementations of List<T> using fixed-size inlined arrays.
Supported for capacities of [8, 16, 32, 64, 128, 256].
ValueList128<int> numbers = [];
for (int n = 0; n < 10; n++) {
numbers.Add(n);
}
Console.WriteLine(string.Join(", ", numbers.Where(number => number % 2 == 0))); // 0, 2, 4, 6, 8
Benchmarks
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| SmallListOfStruct | 27.801 ns | 0.0879 ns | 0.0734 ns | 0.0229 | 144 B |
| SmallValueListOfStruct | 16.547 ns | 0.0379 ns | 0.0354 ns | - | - |
| SmallValueList8OfStruct | 9.331 ns | 0.0180 ns | 0.0160 ns | - | - |
| SmallValueList16OfStruct | 9.552 ns | 0.0178 ns | 0.0158 ns | - | - |
| SmallValueList32OfStruct | 17.032 ns | 0.0394 ns | 0.0369 ns | - | - |
| SmallValueList128OfStruct | 27.538 ns | 0.1100 ns | 0.0975 ns | - | - |
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|
| SmallHashSetOfStruct | 81.87 ns | 0.664 ns | 0.621 ns | 0.0535 | - | - | 336 B |
| SmallValueHashSetOfStruct | 150.36 ns | 0.617 ns | 0.515 ns | - | - | - | - |
| SmallHashSetOfClass | 101.67 ns | 1.273 ns | 1.190 ns | 0.0587 | - | - | 368 B |
| SmallValueHashSetOfClass | 150.27 ns | 0.285 ns | 0.267 ns | - | - | - | - |
| LargeHashSetOfStruct | 141,632.55 ns | 1,615.994 ns | 1,432.536 ns | 95.2148 | 95.2148 | 95.2148 | 538592 B |
| LargeValueHashSetOfStruct | 320,518.52 ns | 786.970 ns | 736.132 ns | - | - | - | - |
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|
| SmallDictionaryOfStructs | 77.02 ns | 0.799 ns | 0.708 ns | 0.0612 | - | - | 384 B |
| SmallValueDictionaryOfStructs | 101.35 ns | 0.160 ns | 0.141 ns | - | - | - | - |
| SmallDictionaryOfClasses | 99.76 ns | 0.205 ns | 0.181 ns | 0.0739 | - | - | 464 B |
| SmallValueDictionaryOfClasses | 178.76 ns | 0.242 ns | 0.202 ns | - | - | - | - |
| LargeDictionaryOfStructs | 163,181.73 ns | 883.658 ns | 737.894 ns | 124.7559 | 124.7559 | 124.7559 | 673026 B |
| LargeValueDictionaryOfStructs | 264,539.87 ns | 968.330 ns | 905.777 ns | - | - | - | - |
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|---|---|---|---|---|---|---|
| SmallStackOfStruct | 16.55 ns | 0.044 ns | 0.037 ns | 0.0127 | - | 80 B |
| SmallValueStackOfStruct | 12.25 ns | 0.044 ns | 0.041 ns | - | - | - |
| SmallStackOfClass | 19.53 ns | 0.126 ns | 0.117 ns | 0.0153 | - | 96 B |
| SmallValueStackOfClass | 16.09 ns | 0.026 ns | 0.025 ns | - | - | - |
| LargeStackOfStruct | 17,901.06 ns | 76.238 ns | 67.583 ns | 20.8130 | 4.1504 | 131400 B |
| LargeValueStackOfStruct | 8,576.68 ns | 11.574 ns | 9.665 ns | - | - | - |
Gotchas
Value collections (except fixed-size 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 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
- No dependencies.
-
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 | |
|---|---|---|---|
| 6.3.0 | 27 | 4/28/2026 | |
| 6.2.0 | 67 | 4/26/2026 | |
| 6.1.0 | 52 | 4/23/2026 | |
| 6.0.0 | 67 | 4/23/2026 | |
| 5.6.0 | 98 | 2/6/2026 | |
| 5.5.0 | 231 | 12/7/2025 | |
| 5.4.0 | 229 | 11/14/2025 | |
| 5.3.0 | 375 | 6/12/2025 | |
| 5.2.0 | 223 | 5/29/2025 | |
| 5.1.0 | 189 | 5/22/2025 | |
| 5.0.0 | 217 | 5/22/2025 | |
| 4.2.0 | 216 | 5/8/2025 | |
| 4.1.0 | 206 | 5/8/2025 | |
| 4.0.0 | 232 | 5/8/2025 | |
| 3.2.0 | 209 | 4/1/2025 | |
| 3.1.0 | 226 | 3/31/2025 | |
| 3.0.0 | 211 | 3/31/2025 | |
| 2.1.0 | 508 | 3/26/2025 | |
| 2.0.0 | 350 | 3/24/2025 | |
| 1.3.0 | 329 | 3/23/2025 |