gpt4 book ai didi

c# - 在 OrderBy 中维护子序列顺序

转载 作者:太空狗 更新时间:2023-10-29 20:58:45 26 4
gpt4 key购买 nike

假设我有一个整数类 Day属性(property)和一个IEnumerable<T>天数为 2、3、4、1、3、3 和 5(按此顺序)的对象。

有没有办法保证子序列的顺序在哪里(例如)o.Day == 3从其元素在原始列表中的相对位置进行维护, 不需要 IEnumerable 的显式自定义实现?

最佳答案

OrderBy 记录为 stable ,如果那是你的意思;所以:你不需要做任何事情。

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.

关于c# - 在 OrderBy 中维护子序列顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19834365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com