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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:04:27+00:00 2026-06-10T07:04:27+00:00

Imagine that you have a list called List<Foo> . Foo is an abstract class,

  • 0

Imagine that you have a list called List<Foo>.

Foo is an abstract class, so this can be FooA, FooB, FooC or FooD. And I’d like to have an extension for List<T> where you can order this elements by type but sequently.

For example, if I have 9 elements in it.

FooA, FooA, FooB, FooD, FooC, FooC, FooA, FooB, FooA

Order by type sequently will be.

FooA, FooB, FooC, FooD, FooA, FooB, FooC, FooA, FooA

I’m trying that the function can be ordered at the order you specify, at this case, IE, it was:

new[] { typeof(FooA), typeof(FooB), typeof(FooC), typeof(FooD) }

I was trying to create this extension, but I don’t get anything. Can you help a little bit? I’m guessing that I can accomplish it with LINQ.

  • 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-10T07:04:27+00:00Added an answer on June 10, 2026 at 7:04 am

    You can group the items by type, sort the groups by type and interleave the groups:

    var groups = items.GroupBy(x => x.GetType())
                      .OrderBy(g => orderedTypes.IndexOf(g.Key))
                      .ToList();
    
    var result = groups.First().Interleave(groups.Skip(1).ToArray());
    

    using the Interleave method from EvenMoreLINQ.

    foreach (var item in result)
    {
        Console.WriteLine(item.GetType());
    }
    

    Output:

    FooA
    FooB
    FooC
    FooD
    FooA
    FooB
    FooC
    FooA
    FooA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that i have a list with a ArrayAdapter like this: When I long
Imagine I have a list of objects that implement an interface called ISummary The
Let's imagine that I have list of files at host1 find /path/to -name *.jpg
Imagine that I have a nice Deck class, in the best OO fashion. It
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
I would like to ask you: Imagine that you have a site and there
Imagine that HTML page is a game surface (see picture). User can have n
Imagine that I have a Debtor class. With Hibernate, I will define the class
I have a class called Part that has 2 fields, PartNo & Filename. I
Imagine that I have a general class Person . Then I have specializations of

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.