Ecng.Collections 1.0.281

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Collections --version 1.0.281
                    
NuGet\Install-Package Ecng.Collections -Version 1.0.281
                    
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.281" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Collections" Version="1.0.281" />
                    
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.281
                    
#r "nuget: Ecng.Collections, 1.0.281"
                    
#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.281
                    
#: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.281
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Collections&version=1.0.281
                    
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.283 1,340 1/26/2026
1.0.282 852 1/22/2026
1.0.281 2,103 1/19/2026
1.0.280 836 1/19/2026
1.0.279 812 1/18/2026
1.0.278 804 1/18/2026
1.0.277 1,437 1/14/2026
1.0.276 867 1/13/2026
1.0.275 819 1/13/2026
1.0.274 1,250 1/9/2026
1.0.273 893 1/9/2026
1.0.272 3,385 1/4/2026
1.0.271 7,329 12/30/2025
1.0.270 9,885 12/29/2025
1.0.269 28,303 12/26/2025
1.0.268 28,311 12/26/2025
1.0.267 28,348 12/26/2025
1.0.266 28,367 12/26/2025
1.0.265 33,850 12/25/2025
1.0.264 35,112 12/25/2025
1.0.263 51,813 12/22/2025
1.0.262 58,822 12/21/2025
1.0.261 67,128 12/19/2025
1.0.260 67,803 12/19/2025
1.0.259 76,184 12/17/2025
1.0.258 90,764 12/15/2025
1.0.257 90,668 12/15/2025
1.0.256 96,929 12/14/2025
1.0.255 117,746 12/12/2025
1.0.254 117,058 12/12/2025
1.0.253 116,672 12/12/2025
1.0.252 116,682 12/12/2025
1.0.251 117,419 12/12/2025
1.0.250 180,561 12/2/2025
1.0.249 180,787 12/2/2025
1.0.248 181,568 12/2/2025
1.0.247 197,138 11/30/2025
1.0.246 200,135 11/29/2025
1.0.245 202,311 11/28/2025
1.0.244 203,017 11/28/2025
1.0.243 206,834 11/27/2025
1.0.242 226,573 11/24/2025
1.0.241 228,322 11/24/2025
1.0.240 233,096 11/23/2025
1.0.239 238,504 11/22/2025
1.0.238 256,613 11/20/2025
1.0.237 279,593 11/18/2025
1.0.236 280,272 11/18/2025
1.0.235 323,027 11/13/2025
1.0.234 355,683 11/10/2025
1.0.233 396,340 11/1/2025
1.0.232 395,588 10/28/2025
1.0.231 395,550 10/27/2025
1.0.230 395,419 10/27/2025
1.0.229 395,350 10/25/2025
1.0.228 445,811 10/3/2025
1.0.227 445,884 9/28/2025
1.0.226 445,628 9/25/2025
1.0.225 469,695 8/30/2025
1.0.224 444,119 7/13/2025
1.0.223 435,614 7/13/2025
1.0.222 435,637 7/12/2025
1.0.221 436,967 7/8/2025
1.0.220 436,431 7/4/2025
1.0.219 435,715 7/2/2025
1.0.218 440,592 6/16/2025
1.0.217 435,870 6/9/2025
1.0.216 435,732 6/8/2025
1.0.215 437,375 5/21/2025
1.0.214 435,846 5/17/2025
1.0.213 437,439 5/12/2025
1.0.212 435,758 5/12/2025
1.0.211 438,227 4/17/2025
1.0.210 440,856 3/22/2025
1.0.209 435,730 3/20/2025
1.0.208 435,671 3/20/2025
1.0.207 435,709 3/19/2025
1.0.206 440,902 2/26/2025
1.0.205 435,793 2/26/2025
1.0.204 444,219 2/5/2025
1.0.203 439,712 1/21/2025
1.0.202 439,075 1/14/2025
1.0.201 437,900 1/12/2025
1.0.200 436,362 1/10/2025
1.0.199 440,027 12/27/2024
1.0.198 436,814 11/20/2024
1.0.197 439,311 11/18/2024
1.0.196 437,624 11/7/2024
1.0.195 437,030 10/19/2024
1.0.194 438,870 10/12/2024
1.0.193 439,423 10/5/2024
1.0.192 440,527 9/18/2024
1.0.191 435,812 9/17/2024
1.0.190 440,220 9/3/2024
1.0.189 435,878 9/1/2024
1.0.188 449,981 6/12/2024
1.0.187 438,729 5/28/2024
1.0.186 439,480 5/4/2024
1.0.185 438,152 4/23/2024
1.0.184 437,238 4/21/2024
1.0.183 436,060 4/14/2024
1.0.182 441,430 3/28/2024
1.0.181 436,011 3/17/2024
1.0.180 439,430 2/23/2024
1.0.179 436,030 2/23/2024
1.0.178 439,411 2/18/2024
1.0.177 436,010 2/18/2024
1.0.176 436,077 2/16/2024
1.0.175 438,171 2/13/2024
1.0.174 437,890 2/8/2024
1.0.173 438,352 2/5/2024
1.0.172 436,053 2/4/2024
1.0.171 438,605 1/23/2024
1.0.170 436,171 1/23/2024
1.0.169 437,877 1/12/2024
1.0.168 441,306 1/2/2024
1.0.167 436,395 12/29/2023
1.0.166 454,585 11/12/2023
1.0.165 847,692 11/10/2023
1.0.164 436,346 11/10/2023
1.0.163 847,383 11/9/2023
1.0.162 848,294 11/3/2023
1.0.161 847,218 11/1/2023
1.0.160 847,271 11/1/2023
1.0.159 872,629 9/8/2023
1.0.158 847,695 9/8/2023
1.0.157 847,943 9/3/2023
1.0.156 848,203 8/21/2023
1.0.155 437,609 8/14/2023
1.0.154 848,724 8/10/2023
1.0.153 888,383 6/29/2023
1.0.152 862,795 5/27/2023
1.0.151 437,298 5/21/2023
1.0.150 437,402 5/19/2023
1.0.149 873,792 5/8/2023
1.0.148 853,706 4/21/2023
1.0.147 899,419 4/3/2023
1.0.146 855,871 3/13/2023
1.0.145 867,714 3/6/2023
1.0.144 849,854 2/26/2023
1.0.143 453,794 2/21/2023
1.0.142 438,195 2/20/2023
1.0.141 439,453 2/15/2023
1.0.140 438,221 2/14/2023
1.0.139 881,679 2/9/2023
1.0.138 454,635 2/7/2023
1.0.137 849,729 2/4/2023
1.0.136 869,797 2/2/2023
1.0.135 866,079 1/30/2023
1.0.134 444,238 1/18/2023
1.0.133 893,444 12/30/2022
1.0.132 851,781 12/23/2022
1.0.131 870,199 12/12/2022
1.0.130 872,832 12/4/2022
1.0.129 850,290 12/4/2022
1.0.128 851,025 11/30/2022
1.0.127 439,404 11/29/2022
1.0.126 439,576 11/28/2022
1.0.125 854,506 11/18/2022
1.0.124 877,762 11/11/2022
1.0.123 850,557 11/11/2022
1.0.122 439,645 11/10/2022
1.0.121 850,829 11/5/2022
1.0.120 852,175 11/4/2022
1.0.119 874,275 11/1/2022
1.0.118 874,563 10/16/2022
1.0.117 857,808 9/10/2022
1.0.116 901,387 9/8/2022
1.0.115 851,081 9/8/2022
1.0.114 440,263 9/8/2022
1.0.113 853,422 9/4/2022
1.0.112 529,866 8/24/2022
1.0.111 860,492 8/8/2022
1.0.110 854,165 7/26/2022
1.0.109 851,312 7/26/2022
1.0.108 903,786 7/19/2022
1.0.107 485,310 7/18/2022
1.0.106 445,396 7/8/2022
1.0.105 855,520 6/18/2022
1.0.104 851,335 6/6/2022
1.0.103 947,897 4/30/2022
1.0.102 851,594 4/20/2022
1.0.101 851,644 4/10/2022
1.0.100 851,624 4/7/2022
1.0.99 851,541 4/7/2022
1.0.98 851,722 4/2/2022
1.0.97 452,108 3/29/2022
1.0.96 443,677 3/27/2022
1.0.95 726,863 1/24/2022
1.0.94 1,010,580 12/29/2021
1.0.93 877,838 12/20/2021
1.0.92 851,262 12/13/2021
1.0.91 907,372 12/6/2021
1.0.90 441,902 12/2/2021
1.0.89 878,956 11/29/2021
1.0.88 877,558 11/22/2021
1.0.87 438,706 11/17/2021
1.0.86 879,404 11/13/2021
1.0.85 442,146 11/10/2021
1.0.84 849,724 11/9/2021
1.0.83 501,278 11/5/2021
1.0.82 851,465 11/4/2021
1.0.81 849,601 11/4/2021
1.0.80 849,534 11/3/2021
1.0.79 849,768 10/30/2021
1.0.78 881,020 10/21/2021
1.0.77 850,201 10/17/2021
1.0.76 910,958 10/14/2021
1.0.75 860,829 10/13/2021
1.0.74 849,799 10/12/2021
1.0.73 881,441 10/11/2021
1.0.72 849,626 10/9/2021
1.0.71 884,800 10/7/2021
1.0.70 886,868 10/7/2021
1.0.69 849,738 10/7/2021
1.0.68 438,883 10/6/2021
1.0.67 849,868 9/28/2021
1.0.66 883,602 9/23/2021
1.0.65 851,494 9/10/2021
1.0.64 849,612 9/9/2021
1.0.63 849,625 9/8/2021
1.0.62 849,749 9/8/2021
1.0.61 880,508 9/6/2021
1.0.60 439,093 8/31/2021
1.0.59 438,865 8/30/2021
1.0.58 882,802 7/31/2021
1.0.57 909,316 7/30/2021
1.0.56 850,080 7/26/2021
1.0.55 938,664 7/5/2021
1.0.54 439,095 7/1/2021
1.0.53 912,189 6/4/2021
1.0.52 939,872 4/26/2021
1.0.51 880,458 4/19/2021
1.0.50 998,463 4/7/2021
1.0.49 879,668 4/3/2021
1.0.48 1,027,691 3/22/2021
1.0.47 961,524 3/4/2021
1.0.46 882,844 2/26/2021
1.0.45 1,016,818 2/2/2021
1.0.44 553,286 1/24/2021
1.0.43 439,566 1/24/2021
1.0.42 439,181 1/23/2021
1.0.41 496,621 1/20/2021
1.0.40 849,980 1/20/2021
1.0.39 467,666 1/18/2021
1.0.38 439,144 1/18/2021
1.0.37 877,127 1/16/2021
1.0.36 966,932 12/16/2020
1.0.35 904,399 12/14/2020
1.0.34 882,176 12/9/2020
1.0.33 852,267 12/6/2020
1.0.32 439,567 12/2/2020
1.0.31 850,275 12/2/2020
1.0.30 878,557 12/1/2020
1.0.29 1,038,888 11/12/2020
1.0.29-atestpub 2,481 11/11/2020
1.0.28 879,580 10/11/2020
1.0.27 961,379 9/9/2020
1.0.26 878,154 9/3/2020
1.0.25 467,879 8/20/2020
1.0.24 933,852 8/9/2020
1.0.23 468,160 7/28/2020
1.0.22 467,121 7/19/2020
1.0.21 494,314 7/6/2020
1.0.20 934,290 6/6/2020
1.0.19 879,318 6/4/2020
1.0.18 495,707 5/29/2020
1.0.17 906,502 5/21/2020
1.0.16 851,117 5/17/2020
1.0.15 905,265 5/12/2020
1.0.14 959,697 5/4/2020
1.0.13 855,205 4/24/2020
1.0.12 857,925 4/22/2020
1.0.11 850,924 4/22/2020
1.0.10 850,949 4/21/2020
1.0.9 880,108 4/18/2020
1.0.8 467,165 4/16/2020
1.0.7 439,970 4/16/2020
1.0.6 873,121 4/15/2020
1.0.5 875,713 4/11/2020
1.0.4 874,604 4/3/2020
1.0.3 439,463 4/1/2020
1.0.2 861,534 3/27/2020
1.0.1 860,560 3/22/2020
1.0.0 442,849 3/22/2020

Add polyfills for netstandard2.0 compatibility