using System.Collections.Generic;
using System.Diagnostics;
public static void Main()
int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19};
Stopwatch s1 = new Stopwatch();
Stopwatch s2 = new Stopwatch();
Stopwatch s3 = new Stopwatch();
Stopwatch s4 = new Stopwatch();
const int iterations = 10000;
for (int i = 0; i < iterations; i++)
int[] result = ConvertToListAndBack(array, 2);
int[] result2 = array.RemoveAt(2);
int[] result3 = RemoveIndices(array, 2);
int[] result4 = LinqSolution(array, 2);
Console.WriteLine("Elapsed time after " + iterations + " iterations:");
Console.WriteLine("Convert to List, use RemoveAt(): " + s1.Elapsed);
Console.WriteLine("RemoveAt extension method: " + s2.Elapsed);
Console.WriteLine("RemoveIndices method: " + s3.Elapsed);
Console.WriteLine("LINQ solution: " + s4.Elapsed);
private static int[] ConvertToListAndBack(int[] array, int removeAt)
var foos = new List<int>(array);
private static int[] RemoveIndices(int[] IndicesArray, int RemoveAt)
int[] newIndicesArray = new int[IndicesArray.Length - 1];
while (i < IndicesArray.Length)
newIndicesArray[j] = IndicesArray[i];
private static int[] LinqSolution(int[] array, int removeAt)
int[] result = array.Where((source, index) => index != removeAt).ToArray();
public static class ExtensionMethods
public static T[] RemoveAt<T>(this T[] source, int index)
T[] dest = new T[source.Length - 1];
Array.Copy(source, 0, dest, 0, index);
if( index < source.Length - 1 )
Array.Copy(source, index + 1, dest, index, source.Length - index - 1);