Implement negative offset, length parameters to T[].Slice(..)

master
Harald Wolff 2019-11-24 15:12:44 +01:00
parent 43a39cb7e4
commit aaf7da496f
1 changed files with 6 additions and 0 deletions

View File

@ -4,6 +4,7 @@ using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Xml.Schema;
namespace ln.types
{
public static class Extensions
@ -260,6 +261,11 @@ namespace ln.types
public static T[] Slice<T>(this T[] me, int offset, int length) => Slice(me, ref offset, length);
public static T[] Slice<T>(this T[] me, ref int offset, int length)
{
if (offset < 0)
offset = me.Length + offset;
if (length < 0)
length = me.Length - offset + length;
T[] slice = new T[length];
Array.Copy(me, offset, slice, 0, length);
offset += length;