Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip the last element in an array and return all other elements C#

Tags:

arrays

c#

skip

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

like image 340
user1290653 Avatar asked Apr 05 '12 19:04

user1290653


People also ask

How do I return an array without the last element?

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.

Which method removes the last element from an array and return it?

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

What is the last element of array in C?

The last element of an array is at position size - 1.


2 Answers

You can't use Skip() in this case but you must use Take().

var result = list.Take(list.Length-1);
like image 173
Omar Avatar answered Sep 25 '22 14:09

Omar


Use Take:

list.Take(list.Length-1);
like image 21
ionden Avatar answered Sep 26 '22 14:09

ionden