c# - Linq在字符串数组上

标签 c# linq

string[] listOne = new string[] { "dog", "cat", "car", "apple"};
string[] listTwo = new string[] { "car", "apple"};


我需要的是按listOne中的项目顺序(如果有)来订购listTwo。因此,新列表将按以下顺序排列:


  “汽车”,“苹果”,“狗”,“猫”

最佳答案

您可以使用扩展方法Union()

var result = listTwo.Union<string>(listOne);

关于c# - Linq在字符串数组上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16765987/

相关文章:

c# - 如何轻松地在 C# Windows 窗体应用程序中添加密码?

c# - 有没有办法将两个 LINQ 查询合并为一个?

c# - 如何从不在 IEnumerable 中的数据表中选择数据

c# - 将表达式类与 LINQ 查询一起使用

c# - NSubstitute - TestFixture 1 在 TestFixture 2 中导致 AmbiguousArgumentsException

c# - 从 MSMQ 读取时无法反序列化 Message.Body

c# - 使用 C# 即时创建 PowerPoint 演示文稿

c# - 为什么使用 AsQueryable() 而不是 List()?

c# - 使用 Linq Select 将实体映射到 DTO 的最简洁方法?

c# - 更新匿名方法中的 ref 参数