Reputation: 11
Can we convert this For-loop into LINQ expresion; both in Query Syntax and Method Syntax ?
List<INode> sds = new List<INode>();
foreach (INode n in lnd)
{
foreach(string s in Pages)
{
if (n.NiceUrl == s)
{
sds.Add(n);
}
}
}
Upvotes: 0
Views: 74
Reputation: 489
sds = lnd.Join(Pages, n => n.NiceUrl, p => p, (n, p) => n).ToList();
Upvotes: 1
Reputation: 9319
Pages.Where(y => lnd.Select(x => x.NiceUrl).Contains(y)).Tolist();
lnd.Select(x => x.NiceUrl) part can be replaced with a HashSet.
Upvotes: 0