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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:02:37+00:00 2026-05-29T09:02:37+00:00

in C# I need to keep data in a dictionary object, looks like: Dictionary<string,

  • 0

in C# I need to keep data in a dictionary object, looks like:

Dictionary<string, Dictionary<string, string>> MyDict = 
    new Dictionary<string, Dictionary<string, string>>();

Now I realised, that I would need in some cases some other (not dictionary-like) data as value of the main dict.

Is there any kind of Problem or limitation, if I just instance the main dict. as:

Dictionary<string, object> MyDict = new Dictionary<string, object>();

in the object field I could put string, dictionary, whatever..

Thanks in advance,
Best regards, Steven

  • 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-29T09:02:39+00:00Added an answer on May 29, 2026 at 9:02 am

    By using object as the value in your dictionary you will incur some risk and complications:

    • Lack of type safety (anything can be set to the value)
    • You would have to cast to a particular type, probably based on the value

    You should probably rethink your design. But if you really want a the flexibility you could create a new type that would work as the value type. Something like:

    class MySpecialType
    {
        public Dictionary<string, string> MyStringDictionary { get; set; }
        public string MyStringVal {get; set;}
    
        public Type ActiveType { get; set; } // property would specify the current type
        // ...
    

    Your main dictionary declaration would then look something like:

    Dictionary<string, MySpecialType> MyDict = new Dictionary<string, MySpecialType>();
    

    You could use the ActiveType property or create an enum which would specify the type. You could also have static util functions in the class which could help with returning the right instance and type…

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

Sidebar

Related Questions

We need to keep some in-memory data structure to keep english word dictionary in
I have a dictionary which I need to keep updated with incoming data, after
I need to keep data like provinces and towns in it, in a DB.
we need to keep track of data modification during the time on some table.
I need to keep a field in a data-base and update it with a
I've got an object that handles in memory caching for my data access layer
Is TRIE the most recommended data structure while designing something like a dictionary for
I need to keep certain data ( in a grid) up to date and
I'm in need of some assistance in traversing three ranges (sheets) and check data
I would like to do an algebraic curve fit of 2D data points, but

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.