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.
You can use array. slice(0,1) // First index is removed and array is returned. FIrst index is not removed, a copy is created without the first element.
The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
Use the array. slice() method to remove the first element from an array, e.g. const withoutFirst = arr. slice(1); . The slice() method will return a shallow copy of the original array starting with the second element.
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()
The following would be equivalent to your for
loop:
foreach (var item in contents.Skip(1))
Message += item;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With