Swap two items in List

前端 未结 5 850
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 05:20

Is there a LINQ way to swap the position of two items inside a list?

5条回答
  •  孤独总比滥情好
    2020-11-30 06:00

    If order matters, you should keep a property on the "T" objects in your list that denotes sequence. In order to swap them, just swap the value of that property, and then use that in the .Sort(comparison with sequence property)

提交回复
热议问题