EndsWith - Kalkwst/Risotto GitHub Wiki

Definition

Determines whether the end of the first sequence is equivalent to the second sequence, optionally using a custom equality comparer.

In this page

Overloads

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.

EndsWith(IEnumerable sequence)

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);

Type Parameters

T
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

sequence IEnumerable <TSource>
The target sequence.

Returns

Boolean
true if source ends with sequence, false otherwise.

Exceptions

ArgumentNullException
source is null

-or-

sequence is null

Example

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

`

EndsWith(IEnumerable sequence, IEqualityComparer? 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, IEqualityComparer<T>? comparer);

Type Parameters

T
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

sequence IEnumerable <TSource>
The target sequence.

comparerIEqualityComparer
An equality comparer to compare values.

Returns

Boolean
true if source ends with sequence, false otherwise.

Exceptions

ArgumentNullException
source is null

-or-

sequence is null

Example

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
⚠️ **GitHub.com Fallback** ⚠️