https://github.com/alastairlundy/enhancedlinq
Additional LINQ style Deferred and Immediate enumeration mode extension methods for .NET .
https://github.com/alastairlundy/enhancedlinq
csharp dotnet dotnet-library linq linq-extensions
Last synced: about 2 months ago
JSON representation
Additional LINQ style Deferred and Immediate enumeration mode extension methods for .NET .
- Host: GitHub
- URL: https://github.com/alastairlundy/enhancedlinq
- Owner: alastairlundy
- License: mpl-2.0
- Created: 2025-07-19T17:08:39.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2026-02-27T11:00:13.000Z (4 months ago)
- Last Synced: 2026-02-27T15:53:23.927Z (3 months ago)
- Topics: csharp, dotnet, dotnet-library, linq, linq-extensions
- Language: C#
- Homepage:
- Size: 1.36 MB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# EnhancedLinq
This library adds Additional LINQ style Deferred execution and Immediate enumeration mode extension methods for .NET.
EnhancedLinq requires dependant projects to use C# language version 14 or newer for EnhancedLinq to work.
## 🚀 Included Methods
For a comprehensive list of included methods, check out the following resources:
- [EnhancedLinq Methods](./docs/Methods/EnhancedLinq.md) [](https://www.nuget.org/packages/EnhancedLinq/) [](https://www.nuget.org/packages/EnhancedLinq/)
- [EnhancedLinqAsync Methods](./docs/Methods/EnhancedLinq.md) [](https://www.nuget.org/packages/EnhancedLinq.Async/) [](https://www.nuget.org/packages/EnhancedLinq.Async/)
- [EnhancedLinq.Memory Methods](./docs/Methods/EnhancedLinq.Memory.md) [](https://www.nuget.org/packages/EnhancedLinq.Memory/) [](https://www.nuget.org/packages/EnhancedLinq.Memory/)
__Note__: The ``EnhancedLinq.MsExtensions`` package has been merged into the base ``EnhancedLinq`` package. To use ``EnhancedLinq.MsExtensions``, install the main ``EnhancedLinq`` package.
## 📦 NuGet Packages
**EnhancedLinq** comes with several packages tailored to your needs:
- **`EnhancedLinq`**: The core package that enhances your LINQ experience. Also includes ``MsExtensions`` sub-namespace for LINQ style methods targetting ``Microsoft.Extensions.Primitives`` types.
- **`EnhancedLinq.Async`**: The IAsyncEnumerable supporting version of EnhancedLinq.
- **`EnhancedLinq.Memory`**: This package is specifically for `Span` and `Memory`, providing helpful immediate mode extensions.
### 🛠️ Installing EnhancedLinq
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 |
|---------------------|-----------------------------------------------------------------------------|------------------------------------------|
| EnhancedLinq | [EnhancedLinq NuGet](https://nuget.org/packages/EnhancedLinq) | `dotnet add package EnhancedLinq` |
| EnhancedLinq.Async | [EnhancedLinq NuGet](https://nuget.org/packages/EnhancedLinq.Async) | `dotnet add package EnhancedLinq.Async` |
| EnhancedLinq.Memory | [EnhancedLinq.Memory NuGet](https://nuget.org/packages/EnhancedLinq.Memory) | `dotnet add package EnhancedLinq.Memory` |
## 📖 Usage
Here are some examples demonstrating how to use some methods provided by EnhancedLinq.
### Deferred Execution Examples
**ElementsAt**
This example shows how to find the elements at a given sequence of indices.
```csharp
var fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry" ];
var indices = [1, 3]; // We want to retrieve "Banana" and "Date"
IEnumerable 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.
```csharp
var numbers = [ 1, 2, 3, 2, 4, 2, 5 ];
int target = 2; // We want to find the indices of the number 2
IEnumerable indices = numbers.IndicesOf(target);
Console.WriteLine("Indices of target element:");
foreach (var index in indices)
{
Console.WriteLine(index); // Outputs: 1, 3, 5
}
```
### Immediate Enumeration Mode Examples
**ContainsDuplicates**
This example shows how to check if an IEnumerable contains any duplicate elements.
```csharp
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.
```csharp
var numbers = new List { 10, 20, 30, 40, 50 };
// Define a predicate to find the first number greater than 25
Func predicate = n => n > 25;
int index = numbers.IndexOf(predicate);
Console.WriteLine($"Zero based index of the first element greater than 25: {index}"); // Output: 2
```
## 🏗️ Building
To build **EnhancedLinq** from source, follow these steps:
1. Clone the repository.
2. Open the solution in your preferred IDE or Code Editor.
3. Build the desired project to restore dependencies and compile the project.
## 🤝 Contributing
I welcome contributions. If you have ideas for new features, improvements, or bug fixes, please check out the [contributing guidelines](./CONTRIBUTING.md) for more information.
## 📜 License
**EnhancedLinq** is licensed under the **MPL 2.0 license**. Feel free to use and modify EnhancedLinq according to the terms of the license.
## ❓ Questions?
If you have any questions or experience any issues, please open a discussion in the [repository's GitHub issues page](https://github.com/alastairlundy/enhancedlinq/discussions).
## 🔄 Alternatives
While **EnhancedLinq** is a powerful tool, you may wish to explore these alternatives:
- [SuperLinq](https://github.com/viceroypenguin/SuperLinq)
- [MoreLinq](https://github.com/morelinq/MoreLINQ)
### Why ``EnhancedLinq`` was created
In no particular order, these are some of the reasons why ``EnhancedLinq`` was created:
* To move DotExtension LINQ style methods/operations to a separate library.
* Hardly any .NET libraries exist that bring Linq style methods/operations to Span/Memory.
* Hardly any .NET libraries exist that bring Linq style methods/operations to StringSegment and other ``Microsoft.Extensions.Primitives`` package types.