gpt4 book ai didi

c# - 未使用 order by 时,Linq to objects join default order 是否指定?

转载 作者:太空狗 更新时间:2023-10-29 21:19:21 25 4
gpt4 key购买 nike

我得到了以下查询

IEnumerable<string> values = from first in goodOrdered
join second in badOrdered on first.ToLower() equals
second.ToLower()
select second;

目前我的测试表明最终结果实际上是 goodOrdered,就像我想要的那样。我可以期望它始终为真,还是我应该提供一个 order by 语句来强制保持 goodOrdered 顺序(这会使查询更复杂,因为 goodOrdered 可能看起来像 1、9、2、7、6)?

最佳答案

是的,确实如此。根据MSDN documentation :

Join preserves the order of the elements of outer, and for each of these elements, the order of the matching elements of inner.

当然,如果文档中没有具体说明那就另当别论了。您可能要考虑的另一个问题是负责维护代码的开发人员,以及您是否希望他们知道/记住 Join 的契约(Contract)包括保留外部序列的顺序......

关于c# - 未使用 order by 时,Linq to objects join default order 是否指定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101730/

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