Skip to content

Commit 0880def

Browse files
Update IEnumerableExtensions.cs
1 parent e04bb75 commit 0880def

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/WouterVanRanst.Utils/Extensions/IEnumerableExtensions.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public static bool Multiple<TSource>(this IEnumerable<TSource> source)
2424
{
2525
// Analogous to Any() but with a check for multiple elements
2626

27-
int count;
28-
return !source.TryGetNonEnumeratedCount<TSource>(out count) ? WithEnumerator(source) : count > 1;
27+
return !source.TryGetNonEnumeratedCount<TSource>(out var count) ? WithEnumerator(source) : count > 1;
2928

3029
#nullable disable
3130
static bool WithEnumerator(IEnumerable<TSource> source)
3231
{
33-
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
34-
return enumerator.MoveNext();
32+
using var enumerator = source.GetEnumerator();
33+
return enumerator.MoveNext();
3534
}
3635
}
3736

@@ -55,6 +54,15 @@ public static bool SequenceEqual<T>(this IEnumerable<T> first, IEnumerable<T> se
5554
}
5655
}
5756

57+
58+
/// <summary>
59+
/// Returns a sequence of elements from the input collection that have duplicates based on the specified key selector.
60+
/// </summary>
61+
/// <typeparam name="T">The type of elements in the collection.</typeparam>
62+
/// <typeparam name="TKey">The type of the key used for comparison.</typeparam>
63+
/// <param name="collection">The input collection.</param>
64+
/// <param name="keySelector">A function to extract the key for comparison.</param>
65+
/// <returns>A sequence of elements that have duplicates based on the specified key selector.</returns>
5866
public static IEnumerable<T> DuplicatesBy<T, TKey>(this IEnumerable<T> collection, Func<T, TKey> keySelector)
5967
{
6068
ArgumentNullException.ThrowIfNull(collection, nameof(collection));

0 commit comments

Comments
 (0)