This library adds Additional LINQ style Deferred execution and Immediate enumeration mode extension methods for .NET .
For a comprehensive list of included methods, check out the following resources:
EnhancedLinq comes with several packages tailored to your needs:
EnhancedLinq
: The core package that enhances your LINQ experience.EnhancedLinq.Memory
: Specifically forSpan<T>
andMemory<T>
, providing helpful immediate mode extensions.EnhancedLinq.MsExtensions
: Focused onStringSegment
fromMicrosoft.Extensions.Primitives
, with plans to potentially expand support for other Microsoft.Extensions packages.
Getting started with EnhancedLinq is easy! You can install the packages using the .NET SDK CLI, your IDE's package manager, or directly from the NuGet website.
Package Id | NuGet Link | .NET SDK CLI Command |
---|---|---|
AlastairLundy.EnhancedLinq.MsExtensions | EnhancedLinq NuGet | dotnet add package AlastairLundy.EnhancedLinq. |
AlastairLundy.EnhancedLinq.EnhancedLinq.Memory | EnhancedLinq.Memory NuGet | dotnet add package AlastairLundy.EnhancedLinq.Memory |
AlastairLundy.EnhancedLinq.EnhancedLinq.MsExtensions | EnhancedLinq.MsExtensions NuGet | dotnet add package AlastairLundy.EnhancedLinq.MsExtensions |
Here are some examples demonstrating how to use some methods provided by EnhancedLinq.
ElementsAt This example shows how to find the elements at a given sequence of indices.
var fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry" ];
var indices = [1, 3]; // We want to retrieve "Banana" and "Date"
IEnumerable<string> selectedFruits = fruits.ElementsAt(indices);
Console.WriteLine("Selected Fruits:");
foreach (string fruit in selectedFruits)
{
Console.WriteLine(fruit); // Outputs: Banana, Date
}
IndicesOf This example shows how to find all the indices of a specific element in an IEnumerable.
var numbers = [ 1, 2, 3, 2, 4, 2, 5 ];
int target = 2; // We want to find the indices of the number 2
IEnumerable<int> indices = numbers.IndicesOf(target);
Console.WriteLine("Indices of target element:");
foreach (var index in indices)
{
Console.WriteLine(index); // Outputs: 1, 3, 5
}
ContainsDuplicates This example shows how to check if an IEnumerable contains any duplicate elements.
var fruits = ["Apple", "Banana", "Cherry", "Apple" ]; // Contains a duplicate
bool hasDuplicates = fruits.ContainsDuplicates();
Console.WriteLine($"Does the list contain duplicates? {hasDuplicates}"); // Output: True
IndexOf This example shows how to find the index of the first element that matches a predicate in an IEnumerable.
var numbers = new List<int> { 10, 20, 30, 40, 50 };
// Define a predicate to find the first number greater than 25
Func<int, bool> predicate = n => n > 25;
int index = numbers.IndexOf(predicate);
Console.WriteLine($"Zero based index of the first element greater than 25: {index}"); // Output: 2
To build EnhancedLinq from source, follow these steps:
- Clone the repository.
- Open the solution in your preferred IDE or Code Editor.
- Build the desired project to restore dependencies and compile the project.
I welcome contributions. If you have ideas for new features, improvements, or bug fixes, please check out the contributing guidelines for more information.
EnhancedLinq is licensed under the Mozilla Public License 2.0. Feel free to use and modify EnhancedLinq according to the terms of the license.
If you have any questions or experience any issues, please open an issue in the repository's GitHub issues page.
While EnhancedLinq is a powerful tool, you may also want to explore these alternatives: