How to remove the first element in an array?

You can easily do that using Skip:

arr = arr.Skip(1).ToArray();  

This creates another array with new elements like in other answers. It's because you can't remove from or add elements to an array. Arrays have a fixed size.


You could try this:

arr = arr.ToList().RemoveAt(0).ToArray();

We make a list based on the array we already have, we remove the element in the 0 position and cast the result to an array.

or this:

arr = arr.Where((item, index)=>index!=0).ToArray();

where we use the overloaded version of Where, which takes as an argument also the item's index. Please have a look here.

Update

Another way, that is more elegant than the above, as D Stanley pointed out, is to use the Skip method:

arr = arr.Skip(1).ToArray(); 

Tags:

C#

Linq

Arrays