C#: LINQ – Equality Comparer

Please see my other LINQ articles. Implement an Equality Comparer to customize Contains(). In this article I’ll demonstrate how to override Contains() when searching a collection to specify which properties of objects to search. First, I’ll get a collection of static People objects. Now, I’ll implement a custom Equality Comparer class where I’ll override Equals() to search…

C#: LINQ – Any() to test a collection

Please see my other LINQ articles. Use Any() to test an entire collection. In this article I’ll demonstrate how to use Any() to determine any object in the collection matches a search predicate. First, I’ll get a collection of static People objects. In the statement, I apply Any() on the people objects’ FirstName property to determine if…

C#: LINQ – All() to test a collection

Please see my other LINQ articles. Use All() to test an entire collection. In this article I’ll demonstrate how to use All() to determine if the entire collection matches a search predicate. First, I’ll get a collection of static People objects. In the statement, I apply All() on the people objects’ LastName property to determine if…

C#: LINQ – Distinct to get unique values

Please see my other LINQ articles. Use Distinct() during select to retrieve a unique list. In this article I’ll demonstrate how to use Distinct() during Select() to generate a unique list of car makes. First, I’ll get a collection of static Car objects. In the section statement, I perform a select on the car objects’ Make property,…

C#: LINQ – SkipWhile to get objects

Please see my other LINQ articles. Use SkipWhile() to include a condition for skipping objects. In this article I’ll demonstrate how to use SkipWhile() to set a condition on which to skip objects when building a collection. First, I’ll get a collection of static Person objects. Now I’ll call SkipWhile() on my collection using Method syntax and…

C#: LINQ – Skip N number objects during get

Please see my other LINQ articles. Use Skip() to ignore n when getting objects. In this article I’ll demonstrate how to use Skip() to ignore a set number of objects when building a collection. First, I’ll get a collection of static Person objects. Now I’ll call Skip() on my collection using Method syntax and only retrieve the…

C#: LINQ – TakeWhile to get objects

Please see my other LINQ articles. Use TakeWhile() to include a condition for getting objects. In this article I’ll demonstrate how to use TakeWhile() to set a condition on which to get a collection of objects . First, I’ll get a collection of static Person objects. Now I’ll call TakeWhile() on my collection using Method syntax and…

C#: LINQ – Take first N number objects

Please see my other LINQ articles. Use Take() to get the first n number of elements. In this article I’ll demonstrate how to use Take() to get a variable number of objects from the front of a collection like the TOP t-sql keyword. First, I’ll get a collection of static Person objects. Now I’ll call Take() on…

C#: LINQ – Set Using Custom Method

Please see my other LINQ articles. Using a Custom Method during a set operation In this article I’ll demonstrate how to call a custom method during a LINQ query. In my previous article, I demonstrated how to use the SET operator during a query. In this example, I’ll perform another set task, but this time using a…

C#: LINQ – Call Custom Method

Please see my other LINQ articles. Using a Custom Method during a Query In this article I’ll demonstrate how to call a custom method during a LINQ query. In my previous article, I demonstrated how to use the SET operator during a query. In this example, I’ll perform another set task, but this time using a custom…