-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Slice.cs
35 lines (34 loc) · 1.33 KB
/
Slice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace SuperLinq;
public static partial class SuperEnumerable
{
/// <summary>
/// Extracts a contiguous count of elements from a sequence at a particular zero-based starting index
/// </summary>
/// <typeparam name="T">
/// The type of the elements in the source sequence
/// </typeparam>
/// <param name="source">
/// The sequence from which to extract elements
/// </param>
/// <param name="startIndex">
/// The zero-based index at which to begin slicing
/// </param>
/// <param name="count">
/// The number of items to slice out of the index
/// </param>
/// <returns>
/// A new sequence containing any elements sliced out from the source sequence
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="source"/> is <see langword="null"/>
/// </exception>
/// <remarks>
/// If the starting position or count specified result in slice extending past the end of the sequence, it will
/// return all elements up to that point. There is no guarantee that the resulting sequence will contain the
/// number of elements requested - it may have anywhere from 0 to <paramref name="count"/>.
/// </remarks>
public static IEnumerable<T> Slice<T>(this IEnumerable<T> source, int startIndex, int count)
{
return source.Take(startIndex..(startIndex + count));
}
}