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 8001349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:04:18+00:00 2026-06-04T16:04:18+00:00

Possible Duplicate: LINQ extension methods – Any() vs. Where() vs. Exists() Given a list

  • 0

Possible Duplicate:
LINQ extension methods – Any() vs. Where() vs. Exists()

Given a list of objects in memory I ran the following two expressions:

myList.where(x => x.Name == "bla").Any() 

vs

myList.Any(x => x.Name == "bla")

The latter was fastest always, I believe this is due to the Where enumerating all items. But this also happens when there’s no matches.

Im not sure of the exact WHY though. Are there any cases where this viewed performance difference wouldn’t be the case, like if it was querying Nhib?

Cheers.

  • 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-06-04T16:04:20+00:00Added an answer on June 4, 2026 at 4:04 pm

    The Any() with the predicate can perform its task without an iterator (yield return). Using a Where() creates an iterator, which adds has a performance impact (albeit very small).

    Thus, performance-wise (by a bit), you’re better off using the form of Any() that takes the predicate (x => x.Name == "bla"). Which, personally, I find more readable as well…

    On a side note, Where() does not necessarily enumerate over all elements, it just creates an iterator that will travel over the elements as they are requested, thus the call to Any() after the Where() will drive the iteration, which will stop at the first item it finds that matches the condition.

    So the performance difference is not that Where() iterates over all the items (in linq-to-objects) because it really doesn’t need to (unless, of course, it doesn’t find one that satisfies it), it’s that the Where() clause has to set up an iterator to walk over the elements, whereas Any() with a predicate does not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Linq .Any VS .Exists - Whats the difference? Is there a performance
Possible Duplicate: Nested “from” LINQ query expressed with extension methods I'm sure this has
Possible Duplicate: How to Count Duplicates in List with LINQ Any idea how do
Possible Duplicate: Why doesn’t VS 2008 display extension methods in Intellisense for String class
Possible Duplicate: LINQ - Where not exists I'm using LINQ2SQL and I want to
Possible Duplicate: LINQ list to sentence format (insert commas & “and”) Imagine these inputs
Possible Duplicates: Sorting a list using Lambda/Linq to objects C# List<> OrderBy Alphabetical Order
Possible Duplicate: Concat all strings inside a List<string> using LINQ I am using C#
Possible Duplicate: string1 >= string2 not implemented in Linq to SQL, any workarround? To
Possible Duplicate: Any chance to get unique records using Linq (C#)? using System; using

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.