Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Array extension, Added additional parameter to specify Array Index (#454
Browse files Browse the repository at this point in the history
)

* New array extension to allow easy addition of information to an existing array

* Updated Extension with additional Array Index option

Co-authored-by: Stephen Hodgson <StephenHodgson@users.noreply.github.com>
  • Loading branch information
SimonDarksideJ and StephenHodgson authored Feb 11, 2020
1 parent 1613834 commit 5037760
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Extensions/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public static bool IsValidArray(this Array array)
/// <param name="array">The array to extend</param>
/// <param name="newItem">The item to add to the array</param>
/// <returns></returns>
public static T[] AddItem<T>(this T[] array, T newItem)
public static T[] AddItem<T>(this T[] array, T newItem, int insertAtIndex = 0)
{
var newArray = new T[array.Length + 1];
array.CopyTo(newArray, 0);
array.CopyTo(newArray, insertAtIndex);
newArray[array.Length] = newItem;
return newArray;
}
Expand Down

0 comments on commit 5037760

Please sign in to comment.