Get all elements but the first from an array
C#LinqC# Problem Overview
Is there a one-line easy linq expression to just get everything from a simple array except the first element?
for (int i = 1; i <= contents.Length - 1; i++)
Message += contents[i];
I just wanted to see if it was easier to condense.
C# Solutions
Solution 1 - C#
Yes, Enumerable.Skip does what you want:
contents.Skip(1)
However, the result is an IEnumerable<T>, if you want to get an array use:
contents.Skip(1).ToArray()
Solution 2 - C#
The following would be equivalent to your for
loop:
foreach (var item in contents.Skip(1))
Message += item;