You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/>.
9
+
/// </summary>
10
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
11
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
12
+
/// <returns>The first element in <paramref name="source"/>.</returns>
13
+
/// <exception cref="InvalidOperationException"><paramref name="source"/> is empty.</exception>
14
+
publicstaticTFirst<T>(thisReadOnlySpan<T>source)
15
+
{
16
+
if(source.IsEmpty)
17
+
{
18
+
thrownewInvalidOperationException($"{nameof(source)} cannot be empty.");
19
+
}
20
+
returnsource[0];
21
+
}
22
+
23
+
/// <summary>
24
+
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/> that satisfies a specified condition.
25
+
/// </summary>
26
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
27
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
28
+
/// <param name="predicate">A function to test each element for a condition.</param>
29
+
/// <returns>The first element in <paramref name="source"/> that passes the test in the specified <paramref name="predicate"/> function.</returns>
30
+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
31
+
/// <exception cref="InvalidOperationException">No element satisfies the condition in <paramref name="predicate"/>. -or- <paramref name="source"/> is empty.</exception>
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/>, or a specified default value if the <see cref="ReadOnlySpan{T}"/> contains no elements..
9
+
/// </summary>
10
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
11
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
12
+
/// <param name="defaultValue">The default value to return if <paramref name="source"/> is empty.</param>
13
+
/// <returns><paramref name="defaultValue"/> if <paramref name="source"/> is empty; otherwise, the first element in <paramref name="source"/>.</returns>
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/> that satisfies a specified condition or a specified default value if no such element is found.
25
+
/// </summary>
26
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
27
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
28
+
/// <param name="predicate">A function to test each element for a condition.</param>
29
+
/// <param name="defaultValue">The default value to return if <paramref name="source"/> is empty.</param>
30
+
/// <returns>default(T) if <paramref name="source"/> is empty or if no element passes the test specified by <paramref name="predicate"/>; otherwise, the first element in <paramref name="source"/> that passes the test specified by <paramref name="predicate"/>.</returns>
31
+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/>, or a specified default value if the <see cref="ReadOnlySpan{T}"/> contains no elements..
56
+
/// </summary>
57
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
58
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
59
+
/// <returns>default(T) if <paramref name="source"/> is empty; otherwise, the first element in <paramref name="source"/>.</returns>
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/> that satisfies a specified conditionor a default value if no such element is found.
71
+
/// </summary>
72
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
73
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
74
+
/// <param name="predicate">A function to test each element for a condition.</param>
75
+
/// <returns>default(T) if <paramref name="source"/> is empty or if no element passes the test specified by <paramref name="predicate"/>; otherwise, the first element in <paramref name="source"/>.</returns>
76
+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
#pragma warning disable CS8603// Possible null reference return.
100
+
/// <summary>
101
+
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/>, or a specified default value if the <see cref="ReadOnlySpan{T}"/> contains no elements..
102
+
/// </summary>
103
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
104
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
105
+
/// <returns>default(T) if <paramref name="source"/> is empty; otherwise, the first element in <paramref name="source"/>.</returns>
/// Returns the first element in a <see cref="ReadOnlySpan{T}"/> that satisfies a specified conditionor a default value if no such element is found.
117
+
/// </summary>
118
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
119
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the first element of.</param>
120
+
/// <param name="predicate">A function to test each element for a condition.</param>
121
+
/// <returns>default(T) if <paramref name="source"/> is empty or if no element passes the test specified by <paramref name="predicate"/>; otherwise, the first element in <paramref name="source"/>.</returns>
122
+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
/// Returns the last element in a <see cref="ReadOnlySpan{T}"/>.
9
+
/// </summary>
10
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
11
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the last element of.</param>
12
+
/// <returns>The last element in <paramref name="source"/>.</returns>
13
+
/// <exception cref="InvalidOperationException"><paramref name="source"/> is empty.</exception>
14
+
publicstaticTLast<T>(thisReadOnlySpan<T>source)
15
+
{
16
+
if(source.IsEmpty)
17
+
{
18
+
thrownewInvalidOperationException($"{nameof(source)} cannot be empty.");
19
+
}
20
+
returnsource[^1];
21
+
}
22
+
23
+
/// <summary>
24
+
/// Returns the last element in a <see cref="ReadOnlySpan{T}"/> that satisfies a specified condition.
25
+
/// </summary>
26
+
/// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
27
+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to return the last element of.</param>
28
+
/// <param name="predicate">A function to test each element for a condition.</param>
29
+
/// <returns>The last element in <paramref name="source"/> that passes the test in the specified <paramref name="predicate"/> function.</returns>
30
+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
31
+
/// <exception cref="InvalidOperationException">No element satisfies the condition in <paramref name="predicate"/>. -or- <paramref name="source"/> is empty.</exception>
0 commit comments