Skip to content

Commit b07694d

Browse files
committed
feat(util): new extension Array.Subarray
1 parent 1da8220 commit b07694d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

AdventOfCode/Solutions/Utilities.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,13 @@ public static void Deconstruct<T>(this IList<T> list, out T first, out T second,
132132

133133
public static IEnumerable<T> IntersectAll<T>(this IEnumerable<IEnumerable<T>> input)
134134
=> input.Aggregate(input.First(), (intersector, next) => intersector.Intersect(next));
135+
136+
public static T[] Subarray<T>(this T[] array, int offset, int length = -1)
137+
{
138+
length = length != -1 ? length : array.Length - offset;
139+
T[] result = new T[length];
140+
Array.Copy(array, offset, result, 0, length);
141+
return result;
142+
}
135143
}
136144
}

0 commit comments

Comments
 (0)