How could I take 1 more item from Linq's TakeWhile?

后端 未结 5 2015
难免孤独
难免孤独 2021-01-01 16:45

(line of code of interest is the last one, the rest is just for a full representation)

Using the following code, I wanted to take VOTERS until I exceeded

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 17:45

    I was facing the same problem. I have used Union and Skip methods, so to take until it was

       IEnumerable newSomethings  = somethings.TakeWhile(s => s != stop).Union(new List(){stop});  
    

    and for skip until

       IEnumerable newSomethings  = somethings.SkipWhile(s => s != stop).Skip(1);  
    

    There is also Take method, which takes some int of first results.

提交回复
热议问题