Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit 7b271f4

Browse files
author
J Burnett
committed
Delegate to reduce actual implementations; improve doc'n comments
1 parent db1c7be commit 7b271f4

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

AMT.LinqExtensions/LinqExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ public static class LinqRandomizer
2121
///<exception cref="System.ArgumentOutOfRangeException">Thrown when the list is empty</exception>
2222
public static T Random<T> (this ICollection<T> elements)
2323
{
24-
return elements.ElementAt(_randomizer.Next(0, elements.Count - 1));
24+
// Delegate to overload taking IEnumerable
25+
return Random<T>(elements as IEnumerable<T>);
2526
}
2627

28+
///<summary>Returns a random element using an enumerable</summary>
29+
///<typeparam name="T">The element type of the enumerable</typeparam>
30+
///<param cref="elements">An IEnumerable of the specified type <seealso cref="T" /></param>
31+
///<exception cref="System.ArgumentOutOfRangeException">Thrown when the list is empty</exception>
2732
public static T Random<T> (this IEnumerable<T> elements)
2833
{
2934
return elements.ElementAt(_randomizer.Next(0, elements.Count() - 1));

0 commit comments

Comments
 (0)