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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:27:53+00:00 2026-06-12T17:27:53+00:00

I have a class that has 3 properties: Name, ID, and ParentID. My data:

  • 0

I have a class that has 3 properties: Name, ID, and ParentID.

My data:

        Name       ID     ParentID
        Event A    1      1
        Event B    2      1
        Event C    3      1
        Event D    4      2

I have everything in a List and was trying to use the OrderBy or perhaps the Sort methods. Not sure which would be better.

I need the data in the list to be ordered so that an event has it’s child as the next item in the list. Any help on this would be greatly appreciated, I am doing this in VB by the way. 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-12T17:27:55+00:00Added an answer on June 12, 2026 at 5:27 pm

    You can sort the list like this

    list.Sort(Function(x, y) 2 * x.ParentID.CompareTo(y.ParentID) + _
                             x.ChildID.CompareTo(y.ChildID))
    

    Explanation: I am using a lambda expression here. You can think of it as a kind of inline declaration of a function. CompareTo returns either -1, 0 or +1. A negative number means x is less than y, 0 both are equal and +1 means x is greater than y. By multiplying the first comparison by two, its sign takes precedence over the second comparison. The second has only an effect, if the first one returns 0.

    The advantage of using the lists Sort method over LINQ is that the list is sorted in-place. With LINQ you would have to create a new list.

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

Sidebar

Related Questions

I have a Website class that has 3 get,set properties ID, Name, URL. For
If I have a Customer class that just has simple properties (e.g. Name ,
I have a class called 'Company' that has properties like 'CompanyName', 'CompanyCode' and 'IsActive'.
I have a c# class that has 20+ string properties. I set about a
I have a class that has an list<Book> in it, and those Book objects
I have a class that has a dozen or so properties that represent various
I have a class that has more than a dozen properties. For most of
Assume I have a class called MyClass that has two properties (int Id and
I have a class called Prescriptions. It has properties that are other classes. So,
I have a domain class User that has at least 20 properties, and it

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.