Ecng.Collections 1.0.278

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Collections --version 1.0.278
                    
NuGet\Install-Package Ecng.Collections -Version 1.0.278
                    
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="Ecng.Collections" Version="1.0.278" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Collections" Version="1.0.278" />
                    
Directory.Packages.props
<PackageReference Include="Ecng.Collections" />
                    
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 Ecng.Collections --version 1.0.278
                    
#r "nuget: Ecng.Collections, 1.0.278"
                    
#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 Ecng.Collections@1.0.278
                    
#: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=Ecng.Collections&version=1.0.278
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Collections&version=1.0.278
                    
Install as a Cake Tool

Ecng.Collections

Thread-safe collections, specialized data structures, and collection utilities for high-performance scenarios.

Thread-Safe Collections

All synchronized collections provide thread-safe operations with internal locking.

SynchronizedDictionary

Thread-safe wrapper around Dictionary<TKey, TValue>.

var dict = new SynchronizedDictionary<int, string>();

// Thread-safe operations
dict[1] = "one";
dict.Add(2, "two");

if (dict.TryGetValue(1, out var value))
    Console.WriteLine(value); // "one"

// Manual locking for compound operations
using (dict.EnterScope())
{
    if (!dict.ContainsKey(3))
        dict.Add(3, "three");
}

SynchronizedList

Thread-safe list with notification support.

var list = new SynchronizedList<string>();

list.Add("item1");
list.AddRange(new[] { "item2", "item3" });

// Safe iteration with scope
using (list.EnterScope())
{
    foreach (var item in list)
        Console.WriteLine(item);
}

CachedSynchronizedList

Thread-safe list that caches its array representation for fast enumeration.

var list = new CachedSynchronizedList<int>();

list.Add(1);
list.Add(2);
list.Add(3);

// Cache is computed once and reused until list changes
int[] cached = list.Cache;
foreach (var item in cached)
    Console.WriteLine(item);

// After modification, cache is invalidated
list.Add(4);
int[] newCache = list.Cache; // Recomputed

CachedSynchronizedDictionary

Thread-safe dictionary with cached key/value arrays.

var dict = new CachedSynchronizedDictionary<string, int>();

dict["a"] = 1;
dict["b"] = 2;

// Cached arrays for fast iteration
string[] keys = dict.CachedKeys;
int[] values = dict.CachedValues;
KeyValuePair<string, int>[] pairs = dict.CachedPairs;

SynchronizedSet

Thread-safe HashSet<T> wrapper.

var set = new SynchronizedSet<int>();

set.Add(1);
set.Add(2);
bool added = set.Add(1); // false, already exists

bool contains = set.Contains(1); // true

Specialized Collections

PairSet - Bidirectional Dictionary

Allows lookup by both key and value.

var pairs = new PairSet<int, string>();

pairs.Add(1, "one");
pairs.Add(2, "two");

// Forward lookup (key -> value)
string value = pairs.GetValue(1); // "one"

// Reverse lookup (value -> key)
int key = pairs.GetKey("two"); // 2

// Check existence
bool hasKey = pairs.ContainsKey(1);
bool hasValue = pairs.ContainsValue("one");

// Remove by value
pairs.RemoveByValue("one");

SynchronizedPairSet

Thread-safe version of PairSet.

var pairs = new SynchronizedPairSet<Guid, string>();

var id = Guid.NewGuid();
pairs.Add(id, "session-1");

// Thread-safe bidirectional lookup
if (pairs.TryGetValue(id, out var session))
    Console.WriteLine(session);

if (pairs.TryGetKey("session-1", out var foundId))
    Console.WriteLine(foundId);

CircularBuffer

Fixed-size buffer that overwrites oldest elements when full.

var buffer = new CircularBuffer<int>(capacity: 3);

buffer.PushBack(1);
buffer.PushBack(2);
buffer.PushBack(3);
// Buffer: [1, 2, 3]

buffer.PushBack(4);
// Buffer: [2, 3, 4] - oldest (1) was overwritten

int front = buffer.Front(); // 2
int back = buffer.Back();   // 4
int second = buffer[1];     // 3

// Remove from ends
buffer.PopFront(); // Removes 2
buffer.PopBack();  // Removes 4

// Convert to array
int[] arr = buffer.ToArray();

// Resize buffer
buffer.Capacity = 5; // Grow
buffer.Capacity = 2; // Shrink (keeps newest elements)

CircularBufferEx

Extended circular buffer with additional operations.

var buffer = new CircularBufferEx<decimal>(100);

// Add elements
buffer.PushBack(1.5m);
buffer.PushBack(2.5m);

// Sum, min, max operations
decimal sum = buffer.Sum;
decimal min = buffer.Min;
decimal max = buffer.Max;

NumericCircularBufferEx

Circular buffer optimized for numeric calculations with running statistics.

var buffer = new NumericCircularBufferEx<double>(100);

for (int i = 0; i < 100; i++)
    buffer.PushBack(Math.Sin(i));

// Efficient statistics (computed incrementally)
double sum = buffer.Sum;
double min = buffer.Min;
double max = buffer.Max;

Queue and Stack Extensions

SynchronizedQueue

Thread-safe queue.

var queue = new SynchronizedQueue<Message>();

queue.Enqueue(new Message("hello"));

if (queue.TryDequeue(out var msg))
    Process(msg);

SynchronizedStack

Thread-safe stack.

var stack = new SynchronizedStack<int>();

stack.Push(1);
stack.Push(2);

if (stack.TryPop(out var value))
    Console.WriteLine(value); // 2

QueueEx / StackEx

Extended queue and stack with additional peek operations.

var queue = new QueueEx<int>();
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);

int first = queue.PeekFirst();  // 1 (front)
int last = queue.PeekLast();    // 3 (back)

Ordered Channels

BaseOrderedChannel

Base class for ordered message processing with channels.

// Used for ordered async message processing
// See ChannelExtensions for usage patterns

Bit Array Operations

BitArrayWriter / BitArrayReader

Efficient bit-level I/O for binary data.

// Writing bits
var writer = new BitArrayWriter();
writer.Write(true);           // 1 bit
writer.Write(42, 8);          // 8 bits
writer.WriteInt(1000);        // Variable-length int

byte[] data = writer.ToArray();

// Reading bits
var reader = new BitArrayReader(data);
bool flag = reader.Read();     // 1 bit
int value = reader.Read(8);    // 8 bits
int number = reader.ReadInt(); // Variable-length int

Collection Interfaces

INotifyList

List that raises events on modifications.

public interface INotifyList<T> : IList<T>
{
    event Action<T> Adding;
    event Action<T> Added;
    event Action<T> Removing;
    event Action<T> Removed;
    event Action Clearing;
    event Action Cleared;
    event Action Changed;
}

ISynchronizedCollection

Interface for thread-safe collections.

public interface ISynchronizedCollection<T> : ICollection<T>
{
    SyncObject SyncRoot { get; }
    LockScope EnterScope();
}

Extension Methods

using Ecng.Collections;

// Check if collection is empty
IEnumerable<int> items = GetItems();
if (items.IsEmpty())
    return;

// Safe first/last
var first = items.FirstOr(defaultValue: -1);
var last = items.LastOr(defaultValue: -1);

// Batch processing
foreach (var batch in items.Batch(100))
    ProcessBatch(batch);

// Index lookup
int index = items.IndexOf(x => x > 10);

NuGet

Install-Package Ecng.Collections
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on Ecng.Collections:

Package Downloads
Ecng.Reflection

Ecng system framework

Ecng.Security

Ecng system framework

Ecng.StringSearch

Ecng system framework

Ecng.Roslyn

Ecng system framework

Ecng.Backup.Mega

Ecng system framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.280 0 1/19/2026
1.0.279 27 1/18/2026
1.0.278 30 1/18/2026
1.0.277 448 1/14/2026
1.0.276 453 1/13/2026
1.0.275 478 1/13/2026
1.0.274 1,198 1/9/2026
1.0.273 876 1/9/2026
1.0.272 3,374 1/4/2026
1.0.271 2,259 12/30/2025
1.0.270 793 12/29/2025
1.0.269 1,216 12/26/2025
1.0.268 802 12/26/2025
1.0.267 783 12/26/2025
1.0.266 800 12/26/2025
1.0.265 857 12/25/2025
1.0.264 874 12/25/2025
1.0.263 1,371 12/22/2025
1.0.262 875 12/21/2025
1.0.261 1,086 12/19/2025
1.0.260 1,730 12/19/2025
1.0.259 10,108 12/17/2025
1.0.258 24,689 12/15/2025
1.0.257 24,599 12/15/2025
1.0.256 30,853 12/14/2025
1.0.255 51,674 12/12/2025
1.0.254 50,989 12/12/2025
1.0.253 50,598 12/12/2025
1.0.252 50,601 12/12/2025
1.0.251 51,340 12/12/2025
1.0.250 114,491 12/2/2025
1.0.249 114,720 12/2/2025
1.0.248 115,492 12/2/2025
1.0.247 131,072 11/30/2025
1.0.246 134,057 11/29/2025
1.0.245 136,237 11/28/2025
1.0.244 136,936 11/28/2025
1.0.243 140,756 11/27/2025
1.0.242 160,490 11/24/2025
1.0.241 162,240 11/24/2025
1.0.240 167,006 11/23/2025
1.0.239 172,426 11/22/2025
1.0.238 190,513 11/20/2025
1.0.237 213,510 11/18/2025
1.0.236 214,187 11/18/2025
1.0.235 256,939 11/13/2025
1.0.234 289,604 11/10/2025
1.0.233 330,263 11/1/2025
1.0.232 329,509 10/28/2025
1.0.231 329,475 10/27/2025
1.0.230 329,340 10/27/2025
1.0.229 329,275 10/25/2025
1.0.228 379,736 10/3/2025
1.0.227 379,813 9/28/2025
1.0.226 379,547 9/25/2025
1.0.225 403,504 8/30/2025
1.0.224 378,040 7/13/2025
1.0.223 369,544 7/13/2025
1.0.222 369,564 7/12/2025
1.0.221 370,823 7/8/2025
1.0.220 370,354 7/4/2025
1.0.219 369,633 7/2/2025
1.0.218 374,515 6/16/2025
1.0.217 369,786 6/9/2025
1.0.216 369,650 6/8/2025
1.0.215 371,292 5/21/2025
1.0.214 369,760 5/17/2025
1.0.213 371,363 5/12/2025
1.0.212 369,679 5/12/2025
1.0.211 372,135 4/17/2025
1.0.210 374,778 3/22/2025
1.0.209 369,647 3/20/2025
1.0.208 369,587 3/20/2025
1.0.207 369,632 3/19/2025
1.0.206 374,814 2/26/2025
1.0.205 369,714 2/26/2025
1.0.204 378,143 2/5/2025
1.0.203 373,636 1/21/2025
1.0.202 372,988 1/14/2025
1.0.201 371,828 1/12/2025
1.0.200 370,274 1/10/2025
1.0.199 373,937 12/27/2024
1.0.198 370,740 11/20/2024
1.0.197 373,224 11/18/2024
1.0.196 371,550 11/7/2024
1.0.195 370,939 10/19/2024
1.0.194 372,798 10/12/2024
1.0.193 373,344 10/5/2024
1.0.192 374,448 9/18/2024
1.0.191 369,735 9/17/2024
1.0.190 374,146 9/3/2024
1.0.189 369,796 9/1/2024
1.0.188 383,905 6/12/2024
1.0.187 372,647 5/28/2024
1.0.186 373,397 5/4/2024
1.0.185 372,079 4/23/2024
1.0.184 371,161 4/21/2024
1.0.183 369,986 4/14/2024
1.0.182 375,351 3/28/2024
1.0.181 369,931 3/17/2024
1.0.180 373,350 2/23/2024
1.0.179 369,952 2/23/2024
1.0.178 373,335 2/18/2024
1.0.177 369,921 2/18/2024
1.0.176 369,998 2/16/2024
1.0.175 372,094 2/13/2024
1.0.174 371,816 2/8/2024
1.0.173 372,278 2/5/2024
1.0.172 369,972 2/4/2024
1.0.171 372,519 1/23/2024
1.0.170 370,087 1/23/2024
1.0.169 371,792 1/12/2024
1.0.168 375,210 1/2/2024
1.0.167 370,306 12/29/2023
1.0.166 388,494 11/12/2023
1.0.165 781,611 11/10/2023
1.0.164 370,272 11/10/2023
1.0.163 781,306 11/9/2023
1.0.162 782,203 11/3/2023
1.0.161 781,137 11/1/2023
1.0.160 781,191 11/1/2023
1.0.159 806,544 9/8/2023
1.0.158 781,615 9/8/2023
1.0.157 781,860 9/3/2023
1.0.156 782,123 8/21/2023
1.0.155 371,531 8/14/2023
1.0.154 782,647 8/10/2023
1.0.153 822,300 6/29/2023
1.0.152 796,717 5/27/2023
1.0.151 371,218 5/21/2023
1.0.150 371,331 5/19/2023
1.0.149 807,707 5/8/2023
1.0.148 787,632 4/21/2023
1.0.147 833,337 4/3/2023
1.0.146 789,800 3/13/2023
1.0.145 801,641 3/6/2023
1.0.144 783,780 2/26/2023
1.0.143 387,715 2/21/2023
1.0.142 372,118 2/20/2023
1.0.141 373,380 2/15/2023
1.0.140 372,134 2/14/2023
1.0.139 815,612 2/9/2023
1.0.138 388,553 2/7/2023
1.0.137 783,660 2/4/2023
1.0.136 803,722 2/2/2023
1.0.135 800,009 1/30/2023
1.0.134 378,156 1/18/2023
1.0.133 827,365 12/30/2022
1.0.132 785,694 12/23/2022
1.0.131 804,124 12/12/2022
1.0.130 806,747 12/4/2022
1.0.129 784,203 12/4/2022
1.0.128 784,952 11/30/2022
1.0.127 373,337 11/29/2022
1.0.126 373,508 11/28/2022
1.0.125 788,429 11/18/2022
1.0.124 811,692 11/11/2022
1.0.123 784,483 11/11/2022
1.0.122 373,575 11/10/2022
1.0.121 784,759 11/5/2022
1.0.120 786,099 11/4/2022
1.0.119 808,205 11/1/2022
1.0.118 808,500 10/16/2022
1.0.117 791,744 9/10/2022
1.0.116 835,316 9/8/2022
1.0.115 785,005 9/8/2022
1.0.114 374,187 9/8/2022
1.0.113 787,347 9/4/2022
1.0.112 463,782 8/24/2022
1.0.111 794,417 8/8/2022
1.0.110 788,080 7/26/2022
1.0.109 785,236 7/26/2022
1.0.108 837,700 7/19/2022
1.0.107 419,237 7/18/2022
1.0.106 379,315 7/8/2022
1.0.105 789,438 6/18/2022
1.0.104 785,257 6/6/2022
1.0.103 881,809 4/30/2022
1.0.102 785,515 4/20/2022
1.0.101 785,565 4/10/2022
1.0.100 785,539 4/7/2022
1.0.99 785,462 4/7/2022
1.0.98 785,649 4/2/2022
1.0.97 386,027 3/29/2022
1.0.96 377,606 3/27/2022
1.0.95 660,730 1/24/2022
1.0.94 944,487 12/29/2021
1.0.93 811,765 12/20/2021
1.0.92 785,183 12/13/2021
1.0.91 841,297 12/6/2021
1.0.90 375,826 12/2/2021
1.0.89 812,885 11/29/2021
1.0.88 811,485 11/22/2021
1.0.87 372,635 11/17/2021
1.0.86 813,314 11/13/2021
1.0.85 376,076 11/10/2021
1.0.84 783,645 11/9/2021
1.0.83 435,207 11/5/2021
1.0.82 785,381 11/4/2021
1.0.81 783,537 11/4/2021
1.0.80 783,451 11/3/2021
1.0.79 783,693 10/30/2021
1.0.78 814,941 10/21/2021
1.0.77 784,121 10/17/2021
1.0.76 844,875 10/14/2021
1.0.75 794,758 10/13/2021
1.0.74 783,710 10/12/2021
1.0.73 815,361 10/11/2021
1.0.72 783,541 10/9/2021
1.0.71 818,717 10/7/2021
1.0.70 820,782 10/7/2021
1.0.69 783,664 10/7/2021
1.0.68 372,798 10/6/2021
1.0.67 783,795 9/28/2021
1.0.66 817,519 9/23/2021
1.0.65 785,416 9/10/2021
1.0.64 783,527 9/9/2021
1.0.63 783,538 9/8/2021
1.0.62 783,661 9/8/2021
1.0.61 814,422 9/6/2021
1.0.60 373,009 8/31/2021
1.0.59 372,784 8/30/2021
1.0.58 816,718 7/31/2021
1.0.57 843,235 7/30/2021
1.0.56 784,000 7/26/2021
1.0.55 872,579 7/5/2021
1.0.54 373,021 7/1/2021
1.0.53 846,105 6/4/2021
1.0.52 873,799 4/26/2021
1.0.51 814,367 4/19/2021
1.0.50 932,378 4/7/2021
1.0.49 813,579 4/3/2021
1.0.48 961,583 3/22/2021
1.0.47 895,442 3/4/2021
1.0.46 816,749 2/26/2021
1.0.45 950,733 2/2/2021
1.0.44 487,202 1/24/2021
1.0.43 373,481 1/24/2021
1.0.42 373,097 1/23/2021
1.0.41 430,521 1/20/2021
1.0.40 783,892 1/20/2021
1.0.39 401,580 1/18/2021
1.0.38 373,060 1/18/2021
1.0.37 811,047 1/16/2021
1.0.36 900,853 12/16/2020
1.0.35 838,323 12/14/2020
1.0.34 816,097 12/9/2020
1.0.33 786,175 12/6/2020
1.0.32 373,484 12/2/2020
1.0.31 784,207 12/2/2020
1.0.30 812,480 12/1/2020
1.0.29 972,804 11/12/2020
1.0.29-atestpub 2,475 11/11/2020
1.0.28 813,497 10/11/2020
1.0.27 895,277 9/9/2020
1.0.26 812,066 9/3/2020
1.0.25 401,798 8/20/2020
1.0.24 867,760 8/9/2020
1.0.23 402,079 7/28/2020
1.0.22 401,030 7/19/2020
1.0.21 428,238 7/6/2020
1.0.20 868,204 6/6/2020
1.0.19 813,240 6/4/2020
1.0.18 429,616 5/29/2020
1.0.17 840,418 5/21/2020
1.0.16 785,031 5/17/2020
1.0.15 839,183 5/12/2020
1.0.14 893,612 5/4/2020
1.0.13 789,114 4/24/2020
1.0.12 791,832 4/22/2020
1.0.11 784,842 4/22/2020
1.0.10 784,863 4/21/2020
1.0.9 814,024 4/18/2020
1.0.8 401,077 4/16/2020
1.0.7 373,890 4/16/2020
1.0.6 807,034 4/15/2020
1.0.5 809,633 4/11/2020
1.0.4 808,520 4/3/2020
1.0.3 373,376 4/1/2020
1.0.2 795,448 3/27/2020
1.0.1 794,484 3/22/2020
1.0.0 376,768 3/22/2020

Fix PairSet bijective property by handling value collisions correctly
Fix WriteLong handling of long.MinValue - use 64 bits instead of 63