ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

SetAllValues

Sets all values.

Source

/// <summary>
/// Sets all values.
/// </summary>
/// <typeparam name="T">The type of the elements of the array that will be modified.</typeparam>
/// <param name="array">The one-dimensional, zero-based array</param>
/// <param name="value">The value.</param>
/// <returns>A reference to the changed array.</returns>
public static T[] SetAllValues<T>(this T[] array, T value)
{
    for (int i = 0; i < array.Length; i++)
    {
        array[i] = value;
    }

    return array;
}

Example

double[] allOnes = new double[10].SetAllValues(1);

Author: Nathan Brown

Submitted on: 15 okt. 2010

Language: C#

Type: System.Array

Views: 6141