I have a list of objects (List1
) and list of string (List2
- list of Names of the objects)
I need to get all objects from List1 if the object.Name does not exists in List2
How can write this LINQ
C#.?
public class Class1
{
public string Name {get;set;}
}
var List1 = new List<Class1>();
var List2 = new List<string>();
var result = List1.Where(x=>!List2.Contains(x.Name)).ToList();
Or:
var result = List1.Where(x=>!List2.Any(n=>n==x.Name)).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With