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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:00:50+00:00 2026-06-15T10:00:50+00:00

I have the following simplified classes: public class BaseContainer { public BaseContainer() { Children

  • 0

I have the following simplified classes:

public class BaseContainer
{
    public BaseContainer()
    {
        Children = new ObservableCollection<BaseContainer>();
    }
    public ObservableCollection<BaseContainer> Children { get; set; }
}

public class ItemA : BaseContainer
{
    public ItemA()
    {
        base.Children.Add(new ItemB() { ItemBName = "bb" });
        base.Children.Add(new ItemA() { ItemAName = "ab" });
        base.Children.Add(new ItemB() { ItemBName = "ba" });
        base.Children.Add(new ItemA() { ItemAName = "aa" });
    }
    public string ItemAName { get; set; }
}

public class ItemB : BaseContainer
{
    public string ItemBName { get; set; }
}

I’m trying to sort my ItemA.Children collection based on two conditions:

  1. All Item A’s must come first in the collection
  2. Item A’s should be sorted by ItemAName
  3. Item B’s should be sorted by ItemBName

So after sorting I’d expect something like this:

  • ItemA – ItemAName = “aa”
  • ItemA – ItemAName = “ab”
  • ItemB – ItemBName = “ba”
  • ItemB – ItemBName = “bb”

Any ideas on how to accomplish this?

I was able to sort by class type name:

        List<BaseContainer> temp = base.Children.ToList();
        temp.Sort((x, y) => string.Compare(x.GetType().Name, y.GetType().Name));
        base.Children.Clear();
        base.Children.AddRange(temp);

But Names are not sorted…

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-15T10:00:52+00:00Added an answer on June 15, 2026 at 10:00 am

    This will get all the A’s, order them by AName, then concat with all the B’s ordered by B name.

    var result = Children.OfType<ItemA>().OrderBy(a => a.ItemAName).Cast<Base>()
        .Concat(Children.OfType<ItemB>().OrderBy(b => b.ItemBName));
    

    I’m not sure this is the design I would go with… you might consider adding something to the base class to facilitate this kind of sorting.

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

Sidebar

Related Questions

I have the following (simplified) classes: public class Person { public string Id {get;
As a simplified example, I have the following data classes: public class Employee {
I have the following (greatly simplified) classes: public class Customer { [Required(ErrorMessageResourceName=Required, ErrorMessageResourceType=typeof(ResourcesCommon.ValidationStrings))] public
I have following data structure (simplified): A giant list of the class TestClass public
I have the following object: public class MyClass { public int Id { get;
i have the following (simplified) domain classes class Filter { String name static hasMany
I have the following classes, they are bit simplified for example. class LineInfo {
Having the following classes (highly simplified): public class Child { public string Label; public
I have the following classes: [Serializable] public class ExtendedAddressData { public String AddressLine1 {
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //

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.