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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:37:23+00:00 2026-06-14T09:37:23+00:00

I have a SortedList in my code. I fill inside it key value pairs.

  • 0

I have a SortedList in my code. I fill inside it key value pairs. When I add an item to SortedList it sorts automatically by key. But i need to sort it by value. Because the values are visible texts in a combobox. They must be alphabetically sorted. I decided to write a class and inherit from SortedList class and override the Add method.

But when I looked at the code of Microsoft’s SortedList class, I see there is an Insert method and it makes the sorting and unfortunately it is private so I cannot override it. Can you help me about this?

Note: I cant use ArrayList or Dictionary or something else. I cannot manage all code in our project. I have to return ‘SortedList‘ or ‘MySortedList‘ derived from SortedList

  • 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-14T09:37:24+00:00Added an answer on June 14, 2026 at 9:37 am

    My first suggestion was to use a custom comparer but his didn’t solve the problem. I therefore investigated SortedList implementaion more detailed and replaced my original post with the following suggestion:

    Overriding the Add method and invoke the private Insert using reflection should do the trick

    private MySortedList()
    {
    }
    
    public override void Add(object key, object value)
    {
        if (key == null || value == null)
        {
            //throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key"));
            throw new ArgumentNullException(); // build your own exception, Environment.GetResourceString is not accessible here
        }
    
        var valuesArray = new object[Values.Count];
        Values.CopyTo(valuesArray , 0);
    
        int index = Array.BinarySearch(valuesArray, 0, valuesArray.Length, value, _comparer);
        if (index >= 0)
        {
            //throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicate__", new object[] { this.GetKey(index), key }));
            throw new ArgumentNullException(); // build your own exception, Environment.GetResourceString is not accessible here
        }
    
        MethodInfo m = typeof(SortedList).GetMethod("Insert", BindingFlags.NonPublic | BindingFlags.Instance);
        m.Invoke(this, new object[] {~index, key, value});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few SortedList<> and SortedDictionary<> structures in my simulation code and I
i have the next list: SortedList<Decimal, KeyValuePair<string,string>> datos; And i need display this in
I have a huge array of ints that I need to sort. The catch
I have an array containing objects that I need to sort, and remove duplicates
I'd like to have a class A with a (for example) SortedList collection SrtdLst
I have tried <display:table name=jobTrackerCol pagesize=20 sort=list id=data requestURI= class=tablelist> <display:column title=Request Id sortable=true
I have written down the following program that uses the quicksort algorithm to sort
I have to create a method which has an ArrayList; I need to remove
I have an order by linq query, something like this like this: var sortedList
I have a list and by making use of datatable plugin I sort them

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.