Remove list elements at given indices

后端 未结 7 920
无人共我
无人共我 2020-12-20 13:19

I have a list which contains some items of type string.

List lstOriginal;

I have another list which contains idices which sh

7条回答
  •  悲&欢浪女
    2020-12-20 13:40

     lstIndices.OrderByDescending(p => p).ToList().ForEach(p => lstOriginal.RemoveAt((int)p));
    

    As a side note, in foreach statements, it is better not to modify the Ienumerable on which foreach is running. The out of range error is probably as a result of this situation.

提交回复
热议问题