tags:

views:

64

answers:

2

I have a string array like this.

string[] queries with data more than one string.

I want to skip the last string from the element and take the remaining. I have come up with

var remStrings = queries.Reverse().Skip(1).Take(queries.Length - 1);

Is there a better alternative to this?

+10  A: 
var remStrings = queries.Take(queries.Length - 1);

No need to Reverse and Skip. Just take one less element than there are in the array.

If you really wanted the elements in the reverse order, you could tack on a .Reverse() to the end.

Justin Niessner
this is good answer.
mohang
+3  A: 

Why not just have:

var remStrings = queries.Take(queries.Length-1);

Which will return them in the same order.

Append .Reverse() to swap the order if that's a necessary requirement:

var remStrings = queries.Take(queries.Length-1).Reverse();
ChrisF