Skip last element in array and return all other c # elements

I would like to return all items except the last item. I looked, maybe using the Skip () method, but got confused. Can anyone help me?

thank

+3


source to share


4 answers


You cannot use Skip()

in this case, but you must use Take()

.



var result = list.Take(list.Length-1);

      

+8


source


Use Take

:



list.Take(list.Length-1);

      

+2


source


You can use Enumerable.Take()

for this:

var results = theArray.Take(theArray.Length - 1);

      

This will allow you to list all the elements except the last one in the array.

0


source


You can do the following:

var array = ...;
var arrayExceptLasElement = array.Take(array.Length-1);

      

Hope it helps!

0


source







All Articles