About 4,230 results
Open links in new tab
  1. Enumerable.FirstOrDefault Method (System.Linq) | Microsoft Learn

    The FirstOrDefault method does not provide a way to specify a default value. If you want to specify a default value other than default(TSource), use the DefaultIfEmpty<TSource> …

  2. When to use .First and when to use .FirstOrDefault with LINQ?

    Jun 22, 2009 · FirstOrDefault () operator returns the first element of a sequence after satisfied the condition. If no element is found then it will return default value of that type.

  3. C# - FirstOrDefault Example (First) - Dot Net Perls

    Sep 21, 2024 · Here we show what happens when FirstOrDefault is used on a non-empty collection, and then an empty collection. If a collection is empty, a default value is returned.

  4. Debunking the Myth: Why Replacing FirstOrDefault is ... - Medium

    Dec 2, 2024 · In this post, we’ll explore why FirstOrDefault is not inherently problematic, where the misunderstanding comes from, and how to approach LINQ performance more thoughtfully.

  5. LINQ in C#: Knowing When to Use First() vs FirstOrDefault()

    Use First () when you expect the sequence to contain at least one matching element, and it would be exceptional if none is found, while FirstOrDefault () is suitable when handling scenarios where no …

  6. First, FirstOrDefault - Element Operators - TutorialsTeacher.com

    The FirstOrDefault method does the same thing as First method. The only difference is that it returns default value of the data type of a collection if a collection is empty or doesn't find any element that …

  7. LINQ First and FirstOrDefault Methods in C# - DEV Community

    Jan 6, 2025 · What is FirstOrDefault ()? FirstOrDefault () is very similar to First (), but with one key difference: it returns a default value when no element matches the condition or if the collection is …

  8. LINQ First and FirstOrDefault Method in C# - Dot Net Tutorials

    In this article, I am going to discuss the LINQ First and FirstOrDefault Methods in C# with Examples using both Method and Query Syntax.

  9. FirstOrDefault | Linq Examples in C#

    C# Linq example of how to find or get the first element or the default item in an array or list using the FirstOrDefault method.

  10. C# – LINQ FirstOrDefault Examples - CSharp Academy

    Jul 19, 2019 · FirstOrDefault is a LINQ functionality to return first element of the collection or default value if requested item does not exist.