Implement negative offset, length parameters to T[].Slice(..)
parent
43a39cb7e4
commit
aaf7da496f
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue