Deadly Nicotine Deadly Nicotine - 1 year ago 62
C# Question

Does LINQ have any easy/elegant way to take the first element and put it at the end?

Or should I say, skip the first element and come back to it at the end.

e.g. say I have

int[] arr = { 2, 4, 3, 9, 1, 0 };

and want to iterate through it like

{ 4, 3, 9, 1, 0, 2 }

I know one way would be like

foreach(int i in arr.Skip(1).Append(new int[] { arr.First() }))

which is why I'm asking whether there's a better looking and/or more efficient way.

Answer Source

Only slightly cleaner than what you've got:

foreach(int i in arr.Skip(1).Concat(arr.Take(1)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download