PosInformatique.Foundations.Collections 1.7.0

Prefix Reserved
dotnet add package PosInformatique.Foundations.Collections --version 1.7.0
                    
NuGet\Install-Package PosInformatique.Foundations.Collections -Version 1.7.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="PosInformatique.Foundations.Collections" Version="1.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PosInformatique.Foundations.Collections" Version="1.7.0" />
                    
Directory.Packages.props
<PackageReference Include="PosInformatique.Foundations.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 PosInformatique.Foundations.Collections --version 1.7.0
                    
#r "nuget: PosInformatique.Foundations.Collections, 1.7.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 PosInformatique.Foundations.Collections@1.7.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=PosInformatique.Foundations.Collections&version=1.7.0
                    
Install as a Cake Addin
#tool nuget:?package=PosInformatique.Foundations.Collections&version=1.7.0
                    
Install as a Cake Tool

PosInformatique.Foundations.Collections

NuGet version NuGet downloads

Introduction

Extensions for .NET collections and sequences. This package supports .NET 8, .NET 9, .NET 10 and .NET 11, trimming and Native AOT. The extensions are in the System.Collections.Generic namespace.

Install

dotnet add package PosInformatique.Foundations.Collections

Usage

Add a sequence of elements to a collection

AddRange() adds each element of an IEnumerable<T> to an ICollection<T> in enumeration order.

using System.Collections.Generic;

ICollection<int> numbers = new List<int> { 1, 2 };
IEnumerable<int> additional = new[] { 3, 4 };
numbers.AddRange(additional); // 1, 2, 3, 4

Create a sequence containing one element

AsSequence() returns a sequence containing exactly the supplied value. If the value is itself a collection, the sequence contains that collection as one element rather than enumerating it.

using System.Collections.Generic;

var sequence = 42.AsSequence(); // A sequence containing 42

Find the index of a matching element

IndexOf() searches an IReadOnlyList<T> and returns the first matching index, or null when no element matches.

using System.Collections.Generic;

IReadOnlyList<int> numbers = new[] { 3, 2, 1 };
int? index = numbers.IndexOf(n => n == 2); // 1

Remove matching elements from a collection

RemoveAll() removes elements matching a predicate from an ICollection<T>. It throws ArgumentException when the collection is read-only.

using System.Collections.Generic;

ICollection<int> numbers = new List<int> { 1, 2, 3, 4 };
numbers.RemoveAll(n => n > 3); // 1, 2, 3

Swap two elements in a list

Swap() exchanges two elements in an IList<T>. An invalid index throws ArgumentOutOfRangeException.

using System.Collections.Generic;

IList<int> list = new List<int> { 1, 2, 3 };
list.Swap(0, 2); // 3, 2, 1

Create a read-only snapshot of a sequence

ToReadOnlyCollection() enumerates any IEnumerable<T>, including an IReadOnlyList<T>, into a new ReadOnlyCollection<T>. Later changes to the source are not reflected in the snapshot.

using System.Collections.Generic;
using System.Collections.ObjectModel;

var source = new List<int> { 1, 2, 3 };
IReadOnlyList<int> list = source;
ReadOnlyCollection<int> snapshot = list.ToReadOnlyCollection();
source.Add(4); // snapshot still contains 1, 2, 3

Null arguments, including the value passed to AsSequence(), throw ArgumentNullException.

When a concrete collection already has an instance method with the same name, C# selects that instance method. Use an ICollection<T> reference to call the collection extensions in that case.

The framework also defines a System.Collections.Generic.CollectionExtensions class. Use extension method syntax as shown above; referring to the class by name is ambiguous when both assemblies are referenced.

Changelog

See CHANGELOG.md for release history.

Product 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.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
1.7.0 51 11/23/2026
1.7.0-rc.1 49 11/23/2026

1.7.0
 - Initial release with collection and sequence extensions, including AsSequence() for a single-element sequence.