IEnumerable<String> existedThings =
from mdinfo in mdInfoTotal select mdinfo.ItemNo;
IEnumerable<String> thingsToSave =
from item in lbXReadSuccess.Items.Cast<ListItem>() select item.Value;
这里有两个IEnumerable
。
我想检查 thingsToSave
中是否存在 value in existedThings
。
好的。我可以用 3 行代码做到这一点。
bool hasItemNo;
foreach(string itemNo in existedThings)
hasItemNo= thingsToSave.Contains(itemNo);
但是,它看起来很脏。
我只是想知道有没有更好的解决方案。
最佳答案
int[] id1 = { 44, 26, 92, 30, 71, 38 };
int[] id2 = { 39, 59, 83, 47, 26, 4, 30 };
IEnumerable<int> both = id1.Intersect(id2);
foreach (int id in both)
Console.WriteLine(id);
//Console.WriteLine((both.Count() > 0).ToString());
Console.WriteLine(both.Any().ToString());
关于c# - 检查两个 IEnumerable 之间是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3013833/