mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 02:25:41 +00:00
Declare Fill for IList<T> not T[]
This commit is contained in:
parent
05dc421487
commit
99bdbccf85
@ -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.
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user