W3Teacher
  • Explore
    Browse by field
    Artificial Intelligence Accounting & Finance Information Technology
    Show all fields
  • Interview Q&A
    • All Interview Questions
    • Beginner
    • Intermediate
    • Advanced
  • Practice
    • MCQs
    • Quizzes
    • Mock Interviews
  • About
  • Sign in
  • Get Started
  1. Home
  2. C#
  3. LINQ
  4. Question
All 18 LINQ questions
More in LINQ
What is LINQ and what is deferred execution? What is LINQ, and what are the two main syntax styles you can use to write a LINQ query? What is the difference between Where() and Select() in a LINQ query? What is the difference between IEnumerable and IQueryable in LINQ? What is the difference between Select and SelectMany? What is 'deferred execution' in LINQ, and how does it differ from calling .ToList() or .ToArray() immediately? How do GroupBy() and its resulting IGrouping<TKey, TElement> work? What is the difference between First(), FirstOrDefault(), Single(), and SingleOrDefault()? What is LINQ, and how does it simplify querying collections compared to writing manual loops? What is the difference between IEnumerable<T>, IQueryable<T>, and List<T>, and how does choosing the wrong one hurt performance against a database?
Advertisement
C# › LINQ

What is the difference between First, FirstOrDefault and Single?

Intermediate

Answer

First returns the first match or throws if none; FirstOrDefault returns default if none; Single expects exactly one and throws otherwise.
var a = xs.First(x => x.Id==1);
var b = xs.FirstOrDefault(x => x.Id==1);
var c = xs.Single(x => x.Id==1);
Real-world example Use Single for a unique-key lookup where duplicates would indicate a data bug.
Previous question What is the difference between IEnumerable and IQueryable in LINQ? Next question What is the difference between Select and SelectMany?
All 18 LINQ questions
W3Teacher

Learn technologies. Ace technical interviews.


    Learn
    • Technologies
    • Tutorials
    • Interview Questions
    • MCQs
    Practice
    • Quizzes
    • Mock Interviews
    • Bookmarks
    • Dashboard
    Get the latest questions & tips

    Fresh interview questions and practice tips, straight to your inbox.

    Company
    • About
    • Contact us
    • Privacy Policy
    • Terms & Conditions

    © 2026 W3Teacher. All rights reserved.