IndexRange 1.0.2

.NET Standard 2.0 .NET Framework 3.5
Install-Package IndexRange -Version 1.0.2
dotnet add package IndexRange --version 1.0.2
<PackageReference Include="IndexRange" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IndexRange --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IndexRange, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install IndexRange as a Cake Addin
#addin nuget:?package=IndexRange&version=1.0.2

// Install IndexRange as a Cake Tool
#tool nuget:?package=IndexRange&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 3.5

  • .NETFramework 4.5

  • .NETFramework 4.7

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (55)

Showing the top 5 NuGet packages that depend on IndexRange:

Package Downloads
EventStore.Client

The client API for Event Store. Get the open source or commercial versions of Event Store server from https://eventstore.com/

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.

Stl

Stl ("ServiceTitan Library") is a collection of relatively small abstractions or methods we couldn't find in BCL. A part of Stl.Fusion.

Stl.Net

Stl.Net - a set of helpers related to networking.

Stl.Testing

Stl.Testing is a collection of testing helpers used by Stl.Fusion tests.

GitHub repositories (12)

Showing the top 5 popular GitHub repositories that depend on IndexRange:

Repository Stars
kwsch/PKHeX
Pokémon Save File Editor
servicetitan/Stl.Fusion
Build real-time apps (Blazor included) with less than 1% of extra code responsible for real-time updates. Host 10-1000x faster APIs relying on transparent and nearly 100% consistent caching. We call it DREAM, or Distributed REActive Memoization, and it's here to turn real-time on!
VerifyTests/Verify
Verify is a snapshot tool that simplifies the assertion of complex data models and documents.
SamboyCoding/Cpp2IL
Work-in-progress tool to reverse unity's IL2CPP toolchain.
gus33000/UUPMediaCreator
An utility to create Windows Media files (.ISO, .WIM, .VHD) from Unified Update Platform files
Version Downloads Last updated
1.0.2 3,401 4/14/2022
1.0.1 5,456 3/5/2022
1.0.1-beta.1 2,898 8/18/2021
1.0.0 231,250 10/4/2019

* Mark assembly as CLS compliant.