Maintain subsequence order in OrderBy

后端 未结 2 720
北荒
北荒 2021-01-05 03:22

Suppose I have a class with an integer Day property and an IEnumerable of objects where the days are 2, 3, 4, 1, 3, 3 and 5 (in that order

2条回答
  •  失恋的感觉
    2021-01-05 04:21

    OrderBy is documented as being stable, if that is what you mean; so: you shouldn't need to do anything.

    Enumerable.OrderBy

    This method performs a stable sort; that is, if the keys of two elements are equal, the order of the elements is preserved. In contrast, an unstable sort does not preserve the order of elements that have the same key.

提交回复
热议问题