时间:2021-07-01 10:21:17 帮助过:28人阅读
List<FileInfo> garbagePicList = new List<FileInfo>();
for (int k = 0; k < fiAllPicList.Length; k++)
{
bool found = false;
for (int l = 0; l < usedPicList.Count; l++)
{
if (fiAllPicList[k].Name == usedPicList[l].ToString())
{
found = true;
}
}
if (!found)
{
garbagePicList.Add(fiAllPicList[k]);
}
}
今天用LINQ重写了一下:
代码如下:
List<FileInfo> garbagePicList = new List<FileInfo>();
var query = from pic in fiAllPicList
where !usedPicList.Contains(pic.Name)
select pic;
garbagePicList = query.ToList();
清晰明了