I have a generic string list that looks something like this:
List<string> list = new List<string>();
list.Add("foo");
list.Add("1");
list.Add("2");
list.Add("bar");
list.Add("foo");
list.Add("1");
list.Add("2");
list.Add("3");
list.Add("bar");
What I would like to know is if there is any way to select whats between two values. In this case I’m after “1”, “2” and “3”. So in other words, i want to select everything between the last “foo” and “bar”. Or perhaps select N rows after “foo” if that’s easier.
My best guess would be the TakeWhile method, but I need your help here.
Taking the last ones is usually a little trickier with LINQ. I’d just go for
LastIndexOffor that part, since you have aList, after all: