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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:14:13+00:00 2026-06-12T07:14:13+00:00

I have an unsorted Dictionary<int, Dictionary<int, string>> and when trying to sort its value’s

  • 0

I have an unsorted Dictionary<int, Dictionary<int, string>> and when trying to sort its value’s Keys its throwing System.ArgumentException: At least one object must implement IComparable. Following is the function,

private static Dictionary<int, Dictionary<int, string>> SortDictionary(Dictionary<int, Dictionary<int, string>> unSortedDict)
{
      var sortedDict = (unSortedDict.OrderBy(entry => entry.Value.Keys)).ToDictionary(pair => pair.Key, pair => pair.Value);

      return sortedDict;
}

I am attaching the data screen shot below where you can see the keys unsorted so you have an idea what i am trying to achieve, surly i am doing something wrong and i need your guidance, thanks

enter image description here

  • 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-12T07:14:15+00:00Added an answer on June 12, 2026 at 7:14 am

    Dictionary is, by design, inherently unsorted. If you sort the dictionary values, then convert it back to a Dictionary, you’ll end up with an unsorted collection again.

    That being said, the error is occuring because you’re trying to call OrderBy with a KeyCollection, which isn’t a sortable type.

    You may want to consider some other collection, such as a SortedDictionary<T,U>. This will require writing a custom comparer to maintain the sort, however.

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

Sidebar

Related Questions

I have unsorted dictionary array and I want to sort it according to artist
How to sort list of date object ? For example I have unsorted list
Assuming I have final Iterable<String> unsorted = asList(FOO, BAR, PREFA, ZOO, PREFZ, PREFOO); What
I have an unsorted dictionary file named dict.txt. I have managed to put the
I have an unsorted list but I want to sort in a custom way
I have an unsorted linked list. To sort it, I thought I'd put the
I have this code: HashMap<String, String[]> unsorted = new HashMap<String, String[]>(); String[] values =
I have an unsorted linked list. I need to sort it by a certain
I have a HTML unsorted list which I capture its on click event. When
I have unsorted map of key value pairs. input = { xa => xavalue,

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.