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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:38:08+00:00 2026-05-17T06:38:08+00:00

Is there any .NET type that would represent a set of key-value pairs where

  • 0

Is there any .NET type that would represent a set of key-value pairs where each key will only be paired with a single value (like a regular Dictionary), but also each value will only be paired with a single key? I’ve been thinking of this as an “invertible” dictionary because you could swap the keys with the values without any collisions. It shouldn’t be hard to write such a class, and add methods like “TryGetKey” for a given value. However, I wanted to check if such a thing already existed somewhere, perhaps under a different name that I haven’t thought of.

Also, considering the elegant answer to this question, would it be worthwhile for me to create a class to represent this invertible dictionary, when I could just as easily use LINQ to convert any dictionary to its value-key equivalent?

  • 1 1 Answer
  • 1 View
  • 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-17T06:38:09+00:00Added an answer on May 17, 2026 at 6:38 am

    I don’t believe there is a class in the framework that does this, directly.

    Also, considering the elegant answer to this question, would it be worthwhile for me to create a class to represent this invertible dictionary, when I could just as easily use LINQ to convert any dictionary to its value-key equivalent?

    The answer to both of your questions really depends on how you are going to be accessing your data. If you need fast, constant time access based on key and value, you are most likely going to want to make your own collection.

    This could be done very, very easily, though. Just wrap two Dictionary instances inside your class, and when you add in a new element, add to both – one with key/value and one with value/key. Your lookup routines can just pull from the appropriate collection, and it will remain near O(1) for access time.

    If, however, memory is more of a concern, you could just use a single collection, and use LINQ to parse it. This is going to make your “reverse” lookup quite a bit slower, as you’ll need to re-parse each time.

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

Sidebar

Related Questions

Is there any Library for .NET that returns SPARQL results in some structured List
is there any custom asp.net membership providers that someone has already created online. I
Is there any possible to connect .NET app with PHP? I means, PHP will
I would like to know if there's any templating engine that is used for
I understand that struct is value type and class is reference type in .Net.
Are there any .NET frameworks for collecting data similar to Google Analytics, for example
I'd like to implement fulltext search for a datatable ? are there any .net
Is there any ASP.NET Membership file Template available ? if it is not available
Is there any library in .Net to convert shapefile to SQL server table? I
Is there any way to render ASP.net MVC controls or code directly within a

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.