我想返回列表中不存在的名称report
。但是我不确定如何IEnumerable<string> names
使用LINQ正确循环。有没有办法使用LINQ遍历另一个数组?
private class Report
{
public string UserName { get; set; }
public string city { get; set; }
public string image { get; set; }
}
List<Report>report = await _service(id).ConfigureAwait(false);
IEnumerable<string> names = await _names(id).ConfigureAwait(false);
// only want to get list of names that do not exist in report
var newList = reports.Where(x => x.UserName.Where(i => != names)); // doesn't work
您可以使用Contains方法。试试:
var newList = reports.Where(x => !names.Contains(x.UserName)));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句