gpt4 book ai didi

c# - Linq在字符串数组上

转载 作者:太空宇宙 更新时间:2023-11-03 17:42:14 25 4
gpt4 key购买 nike

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/

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