IndexRange 1.0.3

This package lets you use the C# 8.0 index and range features in projects that target .NET Framework or netstandard2.0.

Using Range with Arrays

The C# compiler needs the RuntimeHelpers.GetSubArray<T> method to be available to create subranges from arrays. This method is only available in netstandard2.1 and .NET Core 3.0, so creating subranges from arrays will fail to compile in .NET Framework.

Use Span<T>

A workaround is to add a reference to System.Memory and use Span<T>. Not only does this compile, it's much more efficient as it doesn't create a new array and copy the sliced data to it:

int[] array = new[] { 1, 2, 3, 4, 5, 6 };

// don't do this:
// var slice = array[1..^1];

// do this:
var slice = array.AsSpan()[1..^1];

Define GetSubArray<T>

The other fix is to define the necessary method in your source code. Copy the following code into your project:

https://gist.github.com/bgrainger/fb2c18659c2cdfce494c82a8c4803360

That type is not in this NuGet package so that the C# compiler doesn't warn that The predefined type 'RuntimeHelpers' is defined in multiple assemblies.

Showing the top 20 packages that depend on IndexRange.

Packages Downloads
EventStore.Client
The legacy TCP client API for Event Store. Get the open source or commercial versions of Event Store server from https://eventstore.com/
4
EventStore.Client
The client API for Event Store. Get the open source or commercial versions of Event Store server from https://eventstore.com/
3
PhotoSauce.MagicScaler
High-Performance image processing pipeline for .NET. Implements best-of-breed algorithms, linear light processing, and sharpening for the best image resizing quality available. Speed, efficiency, and image quality are unmatched by anything else on the .NET platform.
3
EventStore.Client
The client API for Event Store. Get the open source or commercial versions of Event Store server from https://eventstore.com/
2

* Support uap10.0 target framework. * Use optimized Index.GetOffset in Range.GetOffsetAndLength.

.NET Framework 3.5

.NET Framework 4.5

.NET Framework 4.7

  • No dependencies.

UAP 10.0.10240

.NET Standard 2.0

  • No dependencies.

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
1.0.3 2 10/06/2024
1.0.2 2 10/06/2024
1.0.1 2 10/06/2024
1.0.0 1 11/21/2024