1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 02:45:41 +00:00

Declare Fill for IList<T> not T[]

This commit is contained in:
Oliver Booth 2022-04-25 10:11:42 +01:00
parent 05dc421487
commit 99bdbccf85
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 20 additions and 22 deletions

View File

@ -87,28 +87,6 @@ public static class ArrayExtensions
Array.Clear(array, index, length);
}
/// <summary>
/// Assigns the given value to each element of the array.
/// </summary>
/// <param name="array">The array to be filled.</param>
/// <param name="value">The value to assign to each array element.</param>
/// <typeparam name="T">The type of the elements in the array.</typeparam>
/// <exception cref="ArgumentNullException"><paramref name="array" /> is <see langword="null" />.</exception>
public static void Fill<T>(this T?[] array, T value)
{
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
if (array.Length == 0)
{
return;
}
Array.Fill(array, value);
}
/// <summary>
/// Assigns the given value to the elements of the array which are within the range of <paramref name="startIndex" />
/// (inclusive) and the next <paramref name="count" /> number of indices.

View File

@ -5,6 +5,26 @@
/// </summary>
public static class ListExtensions
{
/// <summary>
/// Assigns the given value to each element of the list.
/// </summary>
/// <param name="source">The list to be filled.</param>
/// <param name="value">The value to assign to each list element.</param>
/// <typeparam name="T">The type of the elements in the list.</typeparam>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static void Fill<T>(this IList<T> source, T value)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
for (var i = 0; i < source.Count; i++)
{
source[i] = value;
}
}
/// <summary>
/// Returns a random element from the current list using a specified <see cref="System.Random" /> instance.
/// </summary>