Removing alternate elements in a List

后端 未结 8 1108
执笔经年
执笔经年 2021-02-12 18:41

What is the most efficient way to remove alternate (odd indexed or even indexed) elements in an List without using a place holder list variable?

A

8条回答
  •  你的背包
    2021-02-12 18:51

    And another option, similar to Frank's one, but with usage of closures. And it is quicker than Frank's version.

    bool isEven = true;            
    var newList = list.Where(x => isEven = !isEven).ToList();
    

提交回复
热议问题