IndexRange 1.1.0
About
This package lets you use the C# 8.0 index and range features in projects that target .NET Framework.
For projects that target netstandard2.0 or .NET Framework 4.6.2 or later, use the Microsoft.Bcl.Memory package instead. This package should be considered deprecated for those target frameworks.
This library is not necessary nor recommended when targeting versions of .NET that include the relevant support.
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 |
|---|---|
|
Masuit.Tools.Abstractions
全龄段友好的C#万能工具库,码数吐司库,不管你是菜鸟新手还是骨灰级玩家都能轻松上手,Masuit.Tools基础公共库(适用于.NET4.6.1/.NET Standard2.0及以上项目),包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。
官网教程:https://masuit.tools
github:https://github.com/ldqk/Masuit.Tools
|
1 |
- Type-forward implementations to Microsoft.Bcl.Memory for netstandard2.0, net462, and higher.
.NET Framework 3.5
- ValueTupleBridge (>= 0.1.5)
.NET Framework 4.5
- System.ValueTuple (>= 4.5.0)
.NET Framework 4.6.2
- Microsoft.Bcl.Memory (>= 9.0.0)
.NET Framework 4.7
- Microsoft.Bcl.Memory (>= 9.0.0)
UAP 10.0.10240
- System.ValueTuple (>= 4.5.0)
.NET Standard 2.0
- Microsoft.Bcl.Memory (>= 9.0.0)
.NET Standard 2.1
- Microsoft.Bcl.Memory (>= 9.0.0)