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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:58:10+00:00 2026-05-12T13:58:10+00:00

It seems that i’m missing something trivial. Anyway, here it goes: var order =

  • 0

It seems that i’m missing something trivial.

Anyway, here it goes:

var order = new[]{1,3,2};
var foos = new[]{new Foo{Id=1}, new Foo{Id=2}, new Foo{Id=3}};

How to sort foos by order array using Linq?

Desired result:

foos == new[]{new Foo{Id=1}, new Foo{Id=3}, new Foo{Id=2}};

Edit:
Order contains Foo ids. Sorry that i didn’t mention that. Sometimes it’s even harder to ask question properly than to answer it. 🙂

  • 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-12T13:58:10+00:00Added an answer on May 12, 2026 at 1:58 pm

    Okay, the question doesn’t seem to be entirely clear to me, so I’ll try to clarify what I think you’re asking:

    • You have a sequence of IDs, in the desired order
    • You have a collection of objects, not in the right order, but with corresponding IDs
    • You want to get the collection of objects in the same order as the ID sequence

    Correct?

    That would be:

    var orderedFoos = from orderedId in order
                      join foo in foos on orderedId equals foo.Id into groups
                      select groups.Single();
    

    You need a join ... into to verify that you don’t have any missing or duplicate IDs in foos. It won’t, however, detect if you’ve got missing or duplicate IDs in order. If you know that everything will be correct (i.e. there will be exactly one entry in foos for every entry in order and vice versa) then a simple join is okay:

    var orderedFoos = from orderedId in order
                      join foo in foos on orderedId equals foo.Id
                      select foo;
    

    which can be expressed in dot notation as:

    var orderedFoos = order.Join(foos, order => order, foo => foo.ID, (o, f) => f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that I'm doing here something terribly wrong. Can you help me? The
It seems that css animations on firefox are pixelating the edges of elements: Here
Seems,that very basic question. Anyway can't get the meaning of next definition from Spring
It seems that I pressed something on the keyboard and these green arrows appeared
Seems that This will be an easy question for you but this problem is
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that we can show layers and even use a different zPosition for
It seems that runClasses() doesn't terminate the code being tested even after the test
It seems that JavaScript's Date() function can only return local date and time. Is
It seems that often I find that my code when moving either from one

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.