How do I select everything in a list after the first occurence of?

c#, linq

Solution

You can use something like this:

var afterTop = fullHierarchy.SkipWhile(x => !x.IsTop).Skip(1);

The `SkipWhile` skips all elements until the first item is found where `IsTop == true`, then the `Skip` skips that element, too. The result will be all items in `fullHierarchy` after the first one where `IsTop == true`.

Problem

I have a collection where each element has a property called IsTop. What I want to do is use linq (if possible) to select everything after the first occurence of IsTop == true. Right now, I do this like this: ``` bool[] foundTop = {false}; // use array for modified closure foreach (var config in fullHierarchy .Where(config => config.IsTop || foundTop[0])) { foundTop[0] = true; configurationHierarchy.Add(config); } ``` I feel like this is a bit contrived. Is there a simpler way to achieve this in LINQ?

Original source