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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:38:04+00:00 2026-06-06T16:38:04+00:00

I need to convert a VB Collection to a modern one, like Dictionary or

  • 0

I need to convert a VB Collection to a modern one, like Dictionary or Hashtable. For my approach, I need the Collection’s KEYS. Googling tells me that it’s impossible.

Re-writing the entire application using new collections is not an option as the application is really old and large (converted from VB6 to VB.Net).
Using the old Collection also is not good – as there are new components in development.

Converting a – for example – Hashtable to Collection works:

 using VBCollection = Microsoft.VisualBasic.Collection;
 public static VBCollection ToVBCollection(this Hashtable table)
    {
        var collection = new VBCollection();
        foreach (DictionaryEntry  pair in table)
        {
            collection.Add(pair.Value, pair.Key as string);
        }
        return collection;
    }

Converting a VBCollection does not, because I don’t know how to retrieve the key:

 using VBCollection = Microsoft.VisualBasic.Collection;
  public static Hashtable ToHashtable(this VBCollection Collection)
    {
        var table = new Hashtable();

        foreach (var pair in Collection)
        {
            table.Add(pair.Key, pair.Value); //I need the key and the corresponding value
        }
        return table;
    }

Any advices? If retrieving the key really is impossible (Thanks, Microsoft), then how should I convert a VB COllection to something modern?

Thanks in advance

  • 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-06T16:38:08+00:00Added an answer on June 6, 2026 at 4:38 pm

    If it is a requirement to have as little impact on your existing codebase as possible, I’d write a drop-in replacement for the Collection. It would be easy (if not a little tedious) to write your own class that exposed all of the same methods as the VB Collection but alos included additional methods to return the keys. You could either inherit from some of the built-in .NET collection types or just use compisition to wrap a Hashtable. You can then change your Imports clauses in your converted VB.NET application to include your Collection intsead of the Microsoft.VisualBasic.Collection.


    For the heck of it, I’ll post an alternate, but more complicated solution. You can use Reflection to get the private Dictionary that the VB Collection object uses internally. With that you could iterate the keys. This is more of a hack than the other approach, but should work equally well. One caveat is that accessing the private members of a class is prone to being broken if MS changes the internals of the class.

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

Sidebar

Related Questions

I have a collection of domain objects that I need to convert into another
I have a collection of paths in canvas and I need to convert them
I need to convert keys from type string to hash. The name of all
I need a way to convert a strings collection into a unique string. This
I need to convert an object to a generic collection, look: var currentEntityProperties =
I need to convert an embedded document onto its own collection, so it can
I need to convert a passed in argument (single object or collection) to an
I need to convert an index generated by Apache Lucene into another collection representation.
I need to convert one array structure into another array structure. I hope someone
I'm using an API that returns a key-value collection as a Dictionary<string, string> .

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.