Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:54:41+00:00 2026-05-27T07:54:41+00:00

Possible Duplicate: When to use .First and when to use .FirstOrDefault with LINQ? What

  • 0

Possible Duplicate:
When to use .First and when to use .FirstOrDefault with LINQ?

What is the point of using the First operator in LINQ, when you could use the FirstOrDefault operator instead?

var q = results.First(); // Error if empty
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:54:41+00:00Added an answer on May 27, 2026 at 7:54 am

    To respond directly to your specific question (why use First if you can always use FirstOrDefault), there are instances where you cannot use FirstOrDefault, because it loses information! The “default value” is likely a valid element type in the source list. You have no way to distinguish between the first element in the enumeration being null/default vs. there being no elements in the list unless you use First or first check if there are Any elements, which requires double-enumeration.

    This is especially true for value-typed enumerables, such as int[]. default(int) is 0, which is also most likely a valid value of the array.

    In general, the two methods represent different logical flows. First would be used if not having any elements is “exceptional” (an error), which then want to handle out-of-band in your application. In this scenario, you “expect” to have at least one element. FirstOrDefault returns null on an empty set, which means you need to do additional processing with the returned value. This is similar logic to the Parse vs TryParse methods on int/double/etc. In fact, your question in some ways leads itself to the more general question of why to ever use exceptions.

    Since First throws an exception, it lends itself to all of the code-reuse opportunities that exceptions provide. For example, you could do:

    try
    {
        x = arr1.First();
        y = arr2.First();
        z = arr3.First();
    }
    catch
    {
        throw new ArgumentException();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I use LINQ Contains(string[]) instead of Contains(string) Suppose I have
Possible Duplicate: Testing use of NSURLConnection with HTTP response error statuses This is bizarre;
Possible Duplicate: Why shall I use the “using” keyword to access my base class
Possible Duplicate: Use autorelease when setting a retain property using dot syntax? What is
Possible Duplicate: Inserting new table row after the first table row using JQuery I
Possible Duplicate: how to test php email using WAMP Hey everyone, First off I
Possible Duplicate: What is the JavaScript >>> operator and how do you use it?
Possible Duplicate: Use of .apply() with 'new' operator. Is this possible? I have 5
Possible Duplicate: Why isn't String.Empty a constant? I can use but not string.Empty when
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.