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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:53:48+00:00 2026-05-17T23:53:48+00:00

To be able to sort a dictionary by value I’m using this code: Dim

  • 0

To be able to sort a dictionary by value I’m using this code:

Dim idCurrentJobs As IDictionary(Of String, Int32) = New Dictionary(Of String, Int32)
'The string in the dictionary represents a jobname and the integer is a counter for how many jobs im currently are running in the application'
idCurrentJobs.Add("JobName1", 2)
idCurrentJobs.Add("JobName2", 1)
idCurrentJobs.Add("JobName3", 2)
idCurrentJobs.Add("JobName4", 5)
idCurrentJobs.Add("JobName5", 3)
idCurrentJobs.Add("JobName6", 4)

Dim jobsSortedByCount As List(Of KeyValuePair(Of String, Int32)) = New List(Of KeyValuePair(Of String, Int32))(idCurrentJobs)
jobsSortedByCount.Sort(Function(firstPair As KeyValuePair(Of String, Int32), nextPair As KeyValuePair(Of String, Int32)) firstPair.Value.CompareTo(nextPair.Value))

idCurrentJobs = jobsSortedByCount.ToDictionary(Of List(Of KeyValuePair(Of String, Int32)))(Function(pair As KeyValuePair(Of String, Int32)) pair.Key)

The when I’m using the .ToDictionary method to convert the List object back to a Directory object I’m getting a error on the “pair.Key” saying:

Value of type ‘String’ cannot be converted to ‘System.Collections.Generic.List(Of System.Collections.Generic.KeyValuePair(Of String, Integer))

How should I use the .ToDictionary to get a Dictionary object from my list of objects?

If i change the row with the .ToDictionary method to this:

idCurrentJobs = jobsSortedByCount.ToDictionary(Of KeyValuePair(Of String, Int32))(Function(pair As KeyValuePair(Of String, Int32)) pair)

I get this error because of “Strict On”:

Option Strict On disallows implicit
conversions from
‘System.Collections.Generic.Dictionary(Of
System.Collections.Generic.KeyValuePair(Of
String, Integer),
System.Collections.Generic.KeyValuePair(Of
String, Integer))’ to
‘System.Collections.Generic.IDictionary(Of
String, Integer)’

How can i solve 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-17T23:53:48+00:00Added an answer on May 17, 2026 at 11:53 pm

    This will work, even with Option Strict On.

    Dim list As List(Of KeyValuePair(Of String, Int32))
    Dim dict As IDictionary(Of String, Int32) = 
        list.ToDictionary(Function(p) p.Key, Function(p) p.Value)
    

    The problem is right here from your code:

    ToDictionary(Of List(Of KeyValuePair(Of String, Int32)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is Microsoft sort.exe 5.1.2600.0 (xpclient.010817-1148) able to sort UTF-16 (LE) files?
Application able to record error in OnError, but we are not able to do
anyone able to tell me how often a materialized view is set to refresh
You should be able to create a generic form: public partial class MyGenericForm<T> :
I'm able to connect to and read an excel file no problem. But when
I want to be able to capture the exception that is thrown when a
I want to be able to do: For Each thing In things End For
I've been able to find details on several self-balancing BST s through several sources,
Has anyone been able to get an NHibernate-based project up and running on a
I need to be able to create basic MS Project items (tasks, projects, resources,

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.