remove an element from the beginning of an array in csharp

To remove the first element of an array in C#, you can shift all the elements after the first one to the left, effectively overwriting the first element. Here's an example:

main.cs
int[] myArray = { 1, 2, 3, 4 };
int[] newArray = new int[myArray.Length-1];
Array.Copy(myArray, 1, newArray, 0, newArray.Length);
130 chars
4 lines

This code creates a new array (newArray) with a length of myArray.Length - 1, and uses Array.Copy to copy all the elements of myArray except for the first one into newArray. At the end of this code, newArray will contain { 2, 3, 4 }, and myArray will still contain { 1, 2, 3, 4 }.

gistlibby LogSnag