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

标签 c# .net linq linq-to-objects

我得到了以下查询

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/

相关文章:

c# - 我可以使用 Microsoft Dotnet CLI 构建 ASP.NET Core Web 应用程序吗?

c# - 如何让 entityFramework 在创建数据库之前询问我;

sql - 如何解决 Linq to SQL 对 DeleteAllOnSubmit 中的每个项目使用单独的 SQL DELETE 语句这一事实

c# - .net dll 是否有像 c++ dll 中的 dll 那样的入口点

c# - 如何从 "Include"表中过滤?

c# - 用于查找 List<List<int>> 最大值的 Linq 表达式?

c# - 在 C# 中的类之间共享对象

当循环位于timer1_Tick函数内部时C#错误

c# - Quickbooks SDK 13.0 ToDoAddRq C#

c# - 如何在 C# 中创建基于 DataTable.Rows.Count 的对象?