我正在尝试将一个字符串列表 (list1) 与下一个列表 (list2) 值(下一个字符串列表)进行比较。我找到了很多关于序列排序的解决方案,但就我而言,这并不重要。
我的字符串列表例如:
List<string> myList1 = new List() {'123', '234','345'}
现在我需要创建一个方法,它将列表“1”作为参数,然后循环(?)遍历列表“2”以检查列表 1 中的值是否在列表 2 中
public bool IsValueInsideTheList(string[] orderNumbersToFindInTheList)
{
//Here I suppose I need to do the looping with foreach/ for to check if value of list1 are in the list2
}
最佳答案
IEnumerable<string> list1;
IEnumerable<string> list2;
// ...
var containsMatches = list1.Any(item => list2.Contains(item));
我用了IEnumerable<string>
在这里是因为这适用于该类型的任何列表,而不仅仅是 List<string>
和一个 string[]
.
https://stackoverflow.com/questions/72953167/