EndsWith - Kalkwst/Risotto GitHub Wiki
Determines whether the end of the first sequence is equivalent to the second sequence, optionally using a custom equality comparer.
In this page
- Definition
- Overloads
- EndsWith(IEnumerable sequence)
- EndsWith(IEnumerable sequence, IEqualityComparer? comparer)
| Overload | Description |
|---|---|
| EndsWith(IEnumerable sequence) | Determines whether the end of the first sequence is equivalent to the second sequence, using the default equality comparer. |
| EndsWith(IEnumerable sequence, IEqualityComparer? comparer) | Determines whether the end of the first sequence is equivalent to the second sequence, using a custom equality comparer. |
Determines whether the end of the first sequence is equivalent to the second sequence, using the default equality comparer.
public static bool EndsWith<T>(this IEnumerable<T> source, IEnumerable<T> sequence);T
The type of the elements of the sequences.
source IEnumerable <TSource>
The source sequence.
sequence IEnumerable <TSource>
The target sequence.
Boolean
true if source ends with sequence, false otherwise.
ArgumentNullException
source is null
-or-
sequence is null
The following code example demonstrates how to use EndsWith(IEnumerable sequence) to check if the a sequence ends with another sequence.
int[] sourceNumbers = new int[] { 1, 2, 3 };
int[] tail1 = new int[] { 2, 3 };
int[] tail2 = new int[] { 1, 2, 3 };
int[] tail3 = new int[] { 0, 1, 2, 3 };
sourceNumbers.EndsWith(tail1);
//=> true
sourceNumbers.EndsWith(tail2);
//=> true
sourceNumbers.EndsWith(tail3);
//=> false`
Determines whether the end of the first sequence is equivalent to the second sequence, using the default equality comparer.
public static bool EndsWith<T>(this IEnumerable<T> source, IEnumerable<T> sequence, IEqualityComparer<T>? comparer);T
The type of the elements of the sequences.
source IEnumerable <TSource>
The source sequence.
sequence IEnumerable <TSource>
The target sequence.
comparerIEqualityComparer
An equality comparer to compare values.
Boolean
true if source ends with sequence, false otherwise.
ArgumentNullException
source is null
-or-
sequence is null
The following code example demonstrates how to use EndsWith(IEnumerable sequence, IEqualityComparer? comparer) to check if the a sequence ends with another sequence.
string[] source = new string[] { "a", "b", "C"};
string[] tail1 = new string[] { "b", "c" };
string[] tail2 = new string[] { "A", "b", "C" };
string[] tail3 = new string[] { "a", "b", "C", "d" };
sourceNumbers.EndsWith(tail1, StringComparer.OrdinalIgnoreCase);
//=> true
sourceNumbers.EndsWith(tail2, StringComparer.OrdinalIgnoreCase);
//=> true
sourceNumbers.EndsWith(tail3, StringComparer.OrdinalIgnoreCase);
//=> false