Use LINQ to get items in one List, that are not in another List

I would assume there’s a simple LINQ query to do this, I’m just not exactly sure how. Given this piece of code: class Program { static void Main(string[] args) { List<Person> peopleList1 = new List<Person>(); peopleList1.Add(new Person() { ID = 1 }); peopleList1.Add(new Person() { ID = 2 }); peopleList1.Add(new Person() { ID = 3 … Read more

Which method performs better: .Any() vs .Count() > 0?

in the System.Linq namespace, we can now extend our IEnumerable’s to have the Any() and Count() extension methods. I was told recently that if i want to check that a collection contains 1 or more items inside it, I should use the .Any() extension method instead of the .Count() > 0 extension method because the … Read more

LINQ query on a DataTable

I’m trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in myDataTable where results.Field(“RowNo”) == 1 select results; This is not allowed. How do I get something like this working? I’m amazed that … Read more