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
You can't use Skip()
in this case but you must use Take()
.
var result = list.Take(list.Length-1);
You can use Enumerable.Take()
for this:
var results = theArray.Take(theArray.Length - 1);
This will let you enumerate all elements except the last in the array.
You can do the following:
var array = ...;
var arrayExceptLasElement = array.Take(array.Length-1);
Hope that helps!
Take()
Jeremy Holovacs 2012-04-05 19:20