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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:55:25+00:00 2026-06-01T19:55:25+00:00

Take var query = Process.GetProcesses() .OrderBy(p => p.WorkingSet64) .ThenByDescending(p => p.Threads.Count); .Where(p => p.ProcessName.Length

  • 0

Take

        var query = Process.GetProcesses()
                            .OrderBy(p => p.WorkingSet64)
                            .ThenByDescending(p => p.Threads.Count);
                            .Where(p => p.ProcessName.Length < 9);

It works fine. Take

        var query = Process.GetProcesses()
                            .OrderBy(p => p.WorkingSet64)
                            .ThenByDescending(p => p.Threads.Count);
                            //.Where(p => p.ProcessName.Length < 9);

        query = query.Where(p => p.ProcessName.Length < 9);

This does not work. I do not understand why the first method works. In my mind these queries are the same. ThenByDescending returns IOrderedEnumerable<T> which is piped into Where(). The first method should not work because Where only works with IEnumerable<T>. Alas…it does work.

How does this processing pipeline function?

  • 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-01T19:55:27+00:00Added an answer on June 1, 2026 at 7:55 pm

    The difference is because of a misunderstanding of the var keyword and LINQ queries.

    var (C# reference)

    Using the var keyword is the same as specifying the same type as the right side of the assignment. It does not mean that you can assign any type to the variable.

    In LINQ queries, most of the basic expressions return an IEnumerable, but it many cases, they do not return just an IEnumerable. Instead, they return an type that inherits from IEnumerable.

    In this case, you are doing the equivalent of this:

    IEnumerable<Process> query = Process.GetProcesses()
                                .OrderBy(p => p.WorkingSet64)
                                .ThenByDescending(p => p.Threads.Count);
                                .Where(p => p.ProcessName.Length < 9);
    

    and

    IOrderedEnumerable<Process> query = Process.GetProcesses()
                                        .OrderBy(p => p.WorkingSet64)
                                        .ThenByDescending(p => p.Threads.Count);
    
    // Won't work because Where doesn't return an IOrderedEnumerable.
    query = query.Where(p => p.ProcessName.Length < 9);
    

    The reason that the first snippet works is because IOrderedEnumerable inherits from IEnumerable, so you can use it as such.

    To fix the problem in the second example, you need to explicitly declare query as IEnumerable<Process>.

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

Sidebar

Related Questions

Take the following linq query: var summary = results.Select(r => new { TotalPopulation =
Take this query: SELECT * FROM MyTable WHERE MyColumn = 'SomeValue' ORDER BY SomeFakeQualifier.MyColumn
I need to take the results of a query: var query = from m
Consider this code: var query = db.Table .Where(t => SomeCondition(t)) .AsEnumerable(); int recordCount =
I saw a ADO.NET EF and LINQ pagging structure like this: var query =
This while parses my query. The $merge var contains the exact structure I need.
I've this Linq query: var query = (from i in session.Query<Photo>() where i.IsApproved ==
Consider this code: var query = from groupRole in CurrentItem.MEMGroupRoles select groupRole.MEMRole; this.AvailableRoles =
Code: var result = db.rows.Take(30).ToList().Select(a => AMethod(a)); db.rows.Take(30) is Linq-To-SQL I am using ToList()
If you take a look at the following JS: (Live: http://jsfiddle.net/RyanWalters/dE6T3/2/ ) var projects

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.