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

  • Home
  • SEARCH
  • 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 302927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:08:31+00:00 2026-05-12T07:08:31+00:00

Are simple LINQ queries on an IEnumerable<T> lightweight or heavyweight? How do they compare

  • 0

Are simple LINQ queries on an IEnumerable<T> lightweight or heavyweight? How do they compare to writing for or foreach loops by hand? Is there a general guideline for when to prefer LINQ versus manual searching?

For example:

var lowNums =
    from n in numbers
    where n < 5
    select n;

Compared to:

List<int> lowNums = new List<int>();

foreach (int n in numbers)
{
    if (n < 5)
    {
        lowNums.Add(n);
    }
}

I was talking to a coworker about LINQ and he expressed some hesitation about using it. He guessed that there might be a lot going on “behind the scenes” in order to support everything LINQ can do.

Is there a significant performance difference between the above examples? Are there any good resources that talk about LINQ performance on collections? A simple Google search for linq performance turned up some seemingly outdated articles.

  • 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-12T07:08:31+00:00Added an answer on May 12, 2026 at 7:08 am

    The authors of LINQ in Action did some benchmarking with for, foreach, List<T>.FindAll, and LINQ queries that all did the same thing. Depending on how the queries were constructed, LINQ was only about 10% slower. As they put it,

    LINQ does not come for free.

    LINQ is a complex subject, but depending on what you do with it, it doesn’t have to add a lot of overhead. Generally LINQ has been built to rely on deferred execution wherever possible, to save memory and CPU until you actually need it.

    However, you have to be aware how the different query operators work, because changing the flow of a query could drastically alter how it’s executed. Simple queries as you describe are usually not a problem, but operators like Reverse() and conversion operators can throw some wrenches because they require immediate iteration of the result set. There are often multiple ways to write the same query, and depending on how you construct it, you can be looking at a minimal performance loss or you could make it twice as slow as the equivalent loops.

    The convienence and conciseness it offers far outweighs any performance considerations for most of my day to day coding though. Never pre-optimize!

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

Sidebar

Related Questions

I'm new to linq and having trouble writing two simple queries. For some reason,
Given the premise: There are competent sql programmers (correlary - writing sql queries are
Is it somehow possible to chain together several LINQ queries on the same IEnumerable
Whats the use of using custom comparers in Linq queries? Are they beneficial or
I'm still learning LINQ. I can do some simple queries, but this one is
I have a simple LINQ query on ADO.NET Entity Framework as follows var result
I have a very simple linq to sql query in C#: int acctNum =
I have a pretty simple Linq to XML query: var q = from c
I want to implement simple LINQ-to-SQL-like functionality in my .net application. For example i
Ive a simple linq query to return records with a null date field, just

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.