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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:35:21+00:00 2026-06-10T17:35:21+00:00

How to sort the given examples. IEnumerable<extra> eList = new List<extra>() { new extra{

  • 0

How to sort the given examples.

        IEnumerable<extra> eList = new List<extra>()
        {
            new extra{ id = 1, text = "a"},
            new extra{ id = 2, text = "g"},
            new extra{ id = 3, text = "i"},
            new extra{ id = 4, text = "e"},
            new extra{ id = 5, text = "f"},
            new extra{ id = 6, text = "d"},
            new extra{ id = 7, text = "c"},
            new extra{ id = 8, text = "h"},
            new extra{ id = 9, text = "b"}
        };

        IEnumerable<sample> sam = new List<sample>()
        {
            new sample{ id = 1, name = "sample 1", list = new List<int>{1,5,6}},
            new sample{ id = 2, name = "sample 1", list = new List<int>{2,9}},
            new sample{ id = 3, name = "sample 1", list = new List<int>{8,3,7}},
            new sample{ id = 4, name = "sample 1", list = new List<int>{3,4,8}},
            new sample{ id = 5, name = "sample 1", list = new List<int>{1,5,7}},
            new sample{ id = 6, name = "sample 1", list = new List<int>{6,9,7}}
        };

I have this code to sort and join the sample list to the extra object above.

           var s2 = (from d1 in sam
                  select new
                  {
                      name = d1.name,
                      id = d1.id,
                      list =
                      (
                         from d2 in d1.list
                         join e in eList on d2 equals e.id
                         select new {  
                             id = d2, text = e.text
                         }
                      ).OrderBy(item => item.text.FirstOrDefault())
                  });

The code above works fine, it joined the two data and sorted the values for the list. But what I want is the output above ‘s2’ will be sorted again by its ‘list’ value by ‘list.text’.

So possible output above must be:

        { id = 1, name = "sample 1", list = {'a','f','d'}},         
        { id = 5, name = "sample 1", list = {'a','f','c'}},
        { id = 2, name = "sample 1", list = {'g','b'}},
        { id = 4, name = "sample 1", list = {'i','e','h'}},
        { id = 6, name = "sample 1", list = {'d','b','c'}},
        { id = 3, name = "sample 1", list = {'h','i','c'}},

Is this possible in LINQ?

thanks

  • 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-10T17:35:22+00:00Added an answer on June 10, 2026 at 5:35 pm
    var newsam = sam.Select(s => new
                     {
                       id = s.id,
                       name = s.name,
                       list = s.list
                               .Select(l => eList.FirstOrDefault(e => e.id == l).text)
                               .OrderBy(e => e)
                               .ToList()
                     }
                    ).OrderBy(s => s.list.FirstOrDefault())
                     .ToList();
    

    EDIT

    So, the inner lists are sorted by the text value of the eList; and the outer list is sorted by the first element of the inner list

    EDIT

              var s2=(from d1 in sam
                      select new
                      {
                          name = d1.name,
                          id = d1.id,
                          list =
                          (
                             from d2 in d1.list
                             join e in eList on d2 equals e.id
                             select e.text
                          ).OrderBy(item => item).ToList()
                      }).OrderBy(item => item.list.FirstOrDefault());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a tabbed delimited text file with two columns name and date: Sam 20100101
I have a necessity to sort a given HTML table of the following structure,
I have read over this which sort of gives an explanation of when you'd
I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy
Given the example queries below (Simplified examples only) DECLARE @DT int; SET @DT=20110717; --
I have been given access to the new shipping api, when creating an app
How can you sort the following word by the given rule? Example data is
Given an array 'a' I would like to sort the array by columns sort(a,
I'm hoping someone has run into this sort of problem before, and can give
So, say I have a string to parse with a given format that maps

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.