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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:49:08+00:00 2026-05-12T00:49:08+00:00

Can anyone help.. I have a generic list like so IList<itemTp> itemTps; itemTp basically

  • 0

Can anyone help.. I have a generic list like so

    IList<itemTp> itemTps;

itemTp basically is a class (has a number of properties) and one property on this is “code”

I need to be able to sort it an specific order which i have set in another List.

This list is a simple list that lists the order (starting from first to last) like say

code1
code3
code2
code5
(notice it goes from 1 to 3 to 2 to 5 – these are the names, they can be called anything .. the important thing is the order, it doesn’t have anything to do with the numbers)

Basically i need ensure the items in itemTp sort according what is present in the other list…

So imagine my Ilist is like this code1,code2,code3,code5 – so once the sort is done
in my

       IList<itemTp>

will contain 4 classes that are in order and have the property like code1,code3,code2,code5 (order change)

Any ideas how to do this?

  • 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-12T00:49:08+00:00Added an answer on May 12, 2026 at 12:49 am

    You’ll need to create an IComparer that will compare items based on the state of your other list. The advantage of using an IComparer is that you’ll be able to build caching logic into your class to avoid repeated IndexOf() lookups if you need that optimization. Also, you’ll be able to maintain multiple “other” lists that can be used when appropriate.

    class ItemTpComparer : IComparer<itemTp>
    {
        private IList<codeTp> otherList;
    
        public ItemTpComparer(IList<codeTp> otherList)
        {
            this.otherList = otherList;
        }
    
        public int Compare(itemTp a, itemTp b)
        {
            return otherList.IndexOf(a.Code) - otherList.IndexOf(b.Code);
        }
    }
    

    And to perform the sort:

    myList.Sort(new ItemTpComparer(otherList));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone suggest some good browser add-on tools/extensions to help with development? I have
Can anyone help? I have a linq query which is embedded inside a extension
Can anyone help? I have a PHP method that sends an http post: <?php
am having problems with some Regex code can anyone help. I have the following
Can anyone help me with the trying to write SQL (MS SqlServer) - I
I just forgot the password. Can anyone help me how to get back the
Wondering if anyone can help me with this annoying but trivial (in terms of
I was wondering if anyone can help me get started with creating a room
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone recommend a good resource -- book, website, article, etc -- to help

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.