<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms" -->

---
title: LINQ and lambda expressions in C# for beginners | daily.dev
description: A beginner-focused walkthrough of LINQ and lambda expressions in C#, covering filtering with Where, projecting with Select, chaining methods, First/Single and...
canonical: https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: LINQ and lambda expressions in C# for beginners | daily.dev
og:description: A beginner-focused walkthrough of LINQ and lambda expressions in C#, covering filtering with Where, projecting with Select, chaining methods, First/Single and...
og:url: https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms
og:image: https://api.daily.dev/og/posts/W1Si8mVmS.png
og:image:alt: LINQ and lambda expressions in C# for beginners
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# LINQ and lambda expressions in C# for beginners

**[Round The Code](https://daily.dev/sources/roundthecode)** · 15 min read · 0 upvotes · 0 comments

## Summary

A beginner-focused walkthrough of LINQ and lambda expressions in C#, covering filtering with Where, projecting with Select, chaining methods, First/Single and their OrDefault variants, ordering with OrderBy/ThenBy, paging with Skip/Take, deduplication with Distinct/DistinctBy, aggregation with Count/Sum/Average, existence checks with Any/All/Contains, Min/Max/MinBy/MaxBy, ElementAt, Reverse, Enumerable.Range, DefaultIfEmpty, list manipulation methods like Concat/Append/Prepend/AddRange, GroupBy, ToDictionary, collection interfaces (IEnumerable, ICollection, IList, List, ReadOnlyCollection), ToList/ToArray, null-conditional operator usage, and method vs query syntax, all demonstrated through a running example of football player records.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.roundthecode.com/dotnet-tutorials/linq-lambda-expressions-csharp-beginners>

## Questions this post answers

### What is the difference between First and Single in C# LINQ?

First returns the first matching record based on list ordering and does not care if more than one match exists, while Single requires exactly one match and throws an InvalidOperationException with the message 'Sequence contains more than one element' if more than one record matches. Both have OrDefault variants (FirstOrDefault, SingleOrDefault) that return null instead of throwing when no match is found.

_daily.dev surfaces C# LINQ guides like this for developers sorting out query edge cases._

### How do I add a secondary sort order when chaining OrderBy calls in LINQ?

Chaining multiple OrderBy calls does not create a secondary sort, since each OrderBy call overrides the previous one. Instead, use ThenBy after the first OrderBy to apply a secondary sort, and ThenByDescending for a descending secondary sort. For example, ordering players by surname length then by date of birth requires OrderBy followed by ThenBy, not two OrderBy calls.

_Developers refining C# sorting logic can find practical LINQ breakdowns like this via daily.dev._

### Why does calling Min or Max on an empty LINQ sequence throw an exception in C#?

Min and Max throw a System.InvalidOperationException with the message 'Sequence contains no elements' when called on a collection with zero matching records, such as filtering a list down to records from a future date range. To avoid this, check whether the sequence has any elements first, or handle the exception, before calling Min or Max directly.

_daily.dev helps C# developers catch these kinds of LINQ runtime pitfalls before they ship._

## Similar posts on daily.dev

- [LINQ in C\#](https://daily.dev/posts/linq-in-c--eoxkvhpkr) · C\# Corner · 36 upvotes · 2 comments
- [One Language to Rule Them? LINQ, Abstraction, and What's Next](https://daily.dev/posts/one-language-to-rule-them-linq-abstraction-and-what-s-next-mon8r0q6p) · We Are .NET · 29 upvotes · 2 comments
- [30 LINQ Interview Questions That Actually Get Asked in 2026](https://daily.dev/posts/30-linq-interview-questions-that-actually-get-asked-in-2026-z9bazqvrc) · Code with Mukesh · 13 upvotes · 1 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"LINQ and lambda expressions in C# for beginners","url":"https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms"},"datePublished":"2026-10-04T13:07:37.090Z","dateModified":"2026-10-04T13:16:20.079Z","description":"A beginner-focused walkthrough of LINQ and lambda expressions in C#, covering filtering with Where, projecting with Select, chaining methods, First/Single and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7803db54bce5518e794c22a37fce905b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7803db54bce5518e794c22a37fce905b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Round The Code","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Round The Code","logo":"https://media.daily.dev/image/upload/s--HmwWBSI1--/f_auto,q_auto/v1791119052/logos/roundthecode?_a=BAMAMicg0","url":"https://daily.dev/sources/roundthecode"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Round The Code","item":"https://daily.dev/sources/roundthecode"},{"@type":"ListItem","position":3,"name":"LINQ and lambda expressions in C# for beginners"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/linq-and-lambda-expressions-in-c-for-beginners-w1si8mvms#faq","mainEntity":[{"@type":"Question","name":"What is the difference between First and Single in C# LINQ?","acceptedAnswer":{"@type":"Answer","text":"First returns the first matching record based on list ordering and does not care if more than one match exists, while Single requires exactly one match and throws an InvalidOperationException with the message 'Sequence contains more than one element' if more than one record matches. Both have OrDefault variants (FirstOrDefault, SingleOrDefault) that return null instead of throwing when no match is found. daily.dev surfaces C# LINQ guides like this for developers sorting out query edge cases."}},{"@type":"Question","name":"How do I add a secondary sort order when chaining OrderBy calls in LINQ?","acceptedAnswer":{"@type":"Answer","text":"Chaining multiple OrderBy calls does not create a secondary sort, since each OrderBy call overrides the previous one. Instead, use ThenBy after the first OrderBy to apply a secondary sort, and ThenByDescending for a descending secondary sort. For example, ordering players by surname length then by date of birth requires OrderBy followed by ThenBy, not two OrderBy calls. Developers refining C# sorting logic can find practical LINQ breakdowns like this via daily.dev."}},{"@type":"Question","name":"Why does calling Min or Max on an empty LINQ sequence throw an exception in C#?","acceptedAnswer":{"@type":"Answer","text":"Min and Max throw a System.InvalidOperationException with the message 'Sequence contains no elements' when called on a collection with zero matching records, such as filtering a list down to records from a future date range. To avoid this, check whether the sequence has any elements first, or handle the exception, before calling Min or Max directly. daily.dev helps C# developers catch these kinds of LINQ runtime pitfalls before they ship."}}]}
```

