I have two lists (for example):
var NewIDs = new List<string>();
NewIDs.AddRange(...some values...);
var OldIDs = new List<some type>()
OldIDs.AddRange(...some values...);
I need to return the OldIDs list, which contains only values from the first one. I do it this way:
var newList = OldIDs.Where(p => p.Id.All(x => NewIDs.Contains(x.ToString()))).ToList();
But it returns count=0;
EDIT 1: NewIDs it's only List of strings, but OldIDs it's some structure, which have an Id propery
EDIT 2: It works this way:
var newList = new List<MyType>();
foreach (var res in NewIDs)
{
newList.AddRange(OldIDs.Where(a => a.Id == res));
}
I need to rewrite it without foreach
, only using LINQ