LINQSamples.com
  • Samples
  • Tutorials
  • About
  • Links
  • Contact
LINQ to Objects

Aggregation

Aggregate, Average, Count, LongCount, Max, Min, Sum

      Aggregate (simple)       Aggregate (seed)       Average       Count       LongCount       Max       Min       Sum

Conversion

AsEnumerable, Cast, OfType, ToArray, ToDictionary, ToList, ToLookup

      AsEnumerable       Cast       OfType       ToArray       ToDictionary (simple)       ToDictionary (conditional)       ToList       ToLookup

Element

ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault

      ElementAt       ElementAtOrDefault       First (simple)       First (conditional)       FirstOrDefault       Last       LastOrDefault (simple)       LastOrDefault (conditional)       Single       SingleOrDefault

Generation

DefaultIfEmpty, Empty, Range, Repeat

      DefaultIfEmpty (simple)       DefaultIfEmpty (default value)       Empty       Range       Repeat

Grouping

GroupBy

      GroupBy

Join

GroupJoin, Join

      GroupJoin (left outer join)       Join (inner join)

Ordering

OrderBy, OrderByDescending, Reverse, ThenBy, ThenByDescending

      OrderBy (simple - numbers)       OrderBy (simple - dates)       OrderBy (simple - objects)       OrderByDescending       Reverse       ThenBy       ThenByDescending

Other

Concat, SequenceEqual, Zip

      Concat (simple - numbers)       Concat (simple - strings)       SequenceEqual       Zip

Partitioning

Skip, SkipWhile, Take, TakeWhile

      Skip       SkipWhile       Take       TakeWhile

Projection

Select, SelectMany

      Select (simple)       Select (anonymous type)       Select (indexed)       SelectMany (cross join)

Quantifiers

All, Any, Contains

      All       Any       Contains

Restriction

Where

      Where (simple - numbers)       Where (simple - objects)       Where (indexed)

Set

Distinct, Except, Intersect, Union

      Distinct       Except       Intersect       Union

LINQ Samples

How to use this compilation of 101 samples

On this site you will find practical 101 code samples of how to use LINQ with both Lambda and Query Expressions. All samples are written in C#, VB.Net and F#.

To the best of my knowledge, all code samples on this site work - but I can't make any guarantees. Should you stumble upon a code snippet which doesn't work, feel free to drop me a mail.

Use the menu on the left side to find easy-to-use code samples.

LINQ

LINQ is part of the Microsoft .NET Framework and is used to query data from specific data providers like LINQ to Objects, LINQ to Entities and LINQ to SQL.

Using LINQ for everyday tasks to query objects and whatever is loaded in memory can be very beneficial, as it may replace many trivial for-each loops and make your code easier to read, understand and maintain.

LINQ to Objects

The LINQ to Objects provider contains a handy set of standard query operators to work with in-memory IEnumerable<T> collections.

Share this sample on:

© 2023 - LINQSamples.com | Terms Of Service  -  Privacy Policy