I have an ordered list like this:
var list = new List<String>(){"aaa","aab","aac","baa","bab","bac"};
I want to cut the list in half and reverse the order of the halves, while retaining the order of the two sub lists. The only way I can think of doing that is like this:
var list = new List<String>() { "aaa", "aab", "aac", "baa", "bab", "bac" };
int index = list.IndexOf("aac");
var tempList = new List<String>(list.GetRange(index, list.Count - index));
tempList.AddRange(list.GetRange(0, index));
list = tempList;
This takes 5 lines and a temporary variable, and doesn’t look very nice.
Is there a neater way to do this? I thought that it should be possible with Linq, but most of those methods don’t seem to care about the order of the underlying list.
Any ideas?
This is probably shorter, but it might be slower: