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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:36:28+00:00 2026-05-19T02:36:28+00:00

I am planning to use multiple name-indexed dictionaries in a project. My first choice

  • 0

I am planning to use multiple name-indexed dictionaries in a project. My first choice was to use a string key, which is just the Name property of my Value elements.

However, this makes the dictionary keys identical even though they are accessing different types:

private Dictionary<string, Foo> myFoos;
private Dictionary<string, Bar> myBars;

myFoos[bar.Name];  // shouldn't be able to do this!

I would like the keys to be type-incompatible with each other to make them impossible to confuse with each other:

private Dictionary<FooName, Foo> myFoos;
private Dictionary<BarName, Bar> myBars;

Since creating a *Name class for each Value type is overkill, I created a Name<T> class:

public struct Name<T>
{
    public string Name;

    // for convenience, could be explicit instead
    static implicit operator string(Name<T> name)
    {
        return name.Name;
    }
}

which would give me

private Dictionary<Name<Foo>, Foo> myFoos;
private Dictionary<Name<Bar>, Bar> myBars;

and then I could store Name<Foo> instances instead of strings.

This seems a bit unwieldy, but it’s the best I’ve come up with so far – any suggestions on how to do it better?
Is this misguided, or awesome?

  • 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-19T02:36:29+00:00Added an answer on May 19, 2026 at 2:36 am

    The first question is:

    I would like the keys to be type-incompatible with each other to make them impossible to confuse with each other:

    Why? Is there actually a chance of confusion? This isn’t obvious. Mind you, I’m not saying that your method is bad; in fact, in fact, there are probably real benefits from this. But consider array indexers:

    int a[];
    float b[];
    

    The types of the arrays are incompatible yet both use integer indices. And yes, this can actually lead to problems when the indices are confused – probably the same kinds of problems that you are facing with your keys.

    So this case is exactly analogous to yours. Perhaps using the same key types for different containers isn’t that bad after all (even though in theory you are right and there’s the risk of confusion).

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

Sidebar

Related Questions

I'm planning to use the Multiple apk approach to my current project, since it
I'm planning to use multiple databases (mongodb, mysql) for my project. And I have
I am planning to use SCTP for a embedded Linux project. Anybody has some
I am planning to use libcurl in my project. I had downloaded the library
I am planning to use PIC18F6*** serial microntroller for my project serial-ethernet converter. Once
I'm planning to use multiple file servers to host my website uploaded files. what's
I'm planning a project for managing multiple distributed databases and I am raising the
I'm re-writing a website that will support multiple skins. Currently, I'm just planning on
I am currently in the process of designing a system which will use multiple
I am planning to develop an mobile app (my first one) for multiple operation

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.