I would like to return all elements but the last element. I looked at maybe using the Skip() method but got confused. Can anyone help me out please?
Thank you
Using the Array pop() Method The Array pop() method is the simplest method used to remove the last element in an array. The pop() method returns the removed element from the original array.
The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
The last element of an array is at position size - 1.
You can't use Skip()
in this case but you must use Take()
.
var result = list.Take(list.Length-1);
Use Take
:
list.Take(list.Length-1);
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