如何比较两个列表并获得不匹配的项目-不使用LINQ [英] How to compare two lists and get unmatching items - without using LINQ
本文介绍了如何比较两个列表并获得不匹配的项目-不使用LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用2个列表,
List<string> localfiles = new List<string>();
List<string> remotefiles = new List<string>();
我需要在远程文件中找到本地文件中不存在的所有新项目.使用LINQ会更容易,但是我不能使用Linq,因为我的应用程序在.net 2.0中.
I need to find all new items in remotefiles that not present in localfiles. Using LINQ it is easier but I cant use Linq as my application is in .net 2.0.
推荐答案
var temp = new List<string>();
foreach(var item in remoteFiles){
if(localfiles.Contains(item) == false){
temp.Add(item);
}
}
//temp现在包含remotefiles中本地文件中不存在的所有项目
//temp now contains all items in remoteFiles that are not present in localfiles
这篇关于如何比较两个列表并获得不匹配的项目-不使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文