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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:37:42+00:00 2026-05-19T23:37:42+00:00

just messing around, trying to expand my bag o’ tricks: I was just experimenting

  • 0

just messing around, trying to expand my bag o’ tricks: I was just experimenting and want to do something like a Dictionary object with another inner Dictionary as the outside Dictionary’s .Value

var dictionary = new Dictionary<ObjectType, Dictionary<string, string>>();

ObjectType is an enum

so…what then…either you’re not suppose to do this or I just don’t know how ’cause I started running into a wall when I was trying to figure out how to populate and retrieve data from it.

Purpose might help: I’m being passed an ObjectGUID and need to flip through a bunch of database tables to determine which table the object exists in. The method I’ve already written just queries each table and returns count (here are a couple examples)

            // Domain Check
        sql = string.Format(@"select count(domainguid) from domains where domainguid = ?ObjectGUID");
        count = (int)MySQLHelper.ExecuteScalar(ConnectionStrings.ConnectionStrings.V4DB_READ, sql, pObjectGUID).ToString().Parse<int>();
        if (count > 0)
            return ObjectType.Domain;

        // Group Check
        sql = string.Format(@"select count(domaingroupguid) from domaingroups where domaingroupguid = ?ObjectGUID");
        count = (int)MySQLHelper.ExecuteScalar(ConnectionStrings.ConnectionStrings.V4DB_READ, sql, pObjectGUID).ToString().Parse<int>();
        if (count > 0)
            return ObjectType.Group;

So, that’s all done and works fine…but because the fieldname and table name are the only things that change for each check I started thinking about where I could re-use the repetitive code, I created a dictionary and a foreach loop that flips through and changes the sql line (shown below)…but, as you can see below, I need that ObjectType as kind of the key for each table/fieldname pair so I can return it without any further calculations

Dictionary<string, string> objects = new Dictionary<string,string>();
            objects.Add("domains", "domainguid");
            objects.Add("domaingroups", "domaingroupguid");
            objects.Add("users", "userguid");
            objects.Add("channels", "channelguid");
            objects.Add("categorylists", "categorylistguid");
            objects.Add("inboundschemas", "inboundschemaguid");
            objects.Add("catalogs", "catalogguid");

            foreach (var item in objects)
            {
                sql = string.Format(@"select count({0}) from {1} where {0} = ?ObjectGUID", item.Value, item.Key);
                count = (int)MySQLHelper.ExecuteScalar(ConnectionStrings.ConnectionStrings.V4DB_READ, sql, pObjectGUID).ToString().Parse<int>();
                if (count > 0)
 return ?????
                }

This isn’t all that important since my original method works just fine but I thought you StackOverflow geeks might turn me on to some new clever ideas to research…I’m guessing someone is going to smack me in the head and tell me to use arrays… 🙂

EDIT @ Jon Skeet ——————————————

Heh, sweet, think I might have come upon the right way to do it…haven’t run it yet but here’s an example I wrote for you

var objectTypes = new Dictionary<string, string>();
        objectTypes.Add("domainguid", "domains");
        var dictionary = new Dictionary<ObjectType, Dictionary<string, string>>();
        dictionary.Add(ObjectType.Domain, objectTypes);

        foreach(var objectType in dictionary)
        {
            foreach(var item in objectType.Value)
            {
                sql = string.Format(@"select count({0}) from {1} where {0} = ?ObjectGUID", item.Key, item.Value);
                count = (int)MySQLHelper.ExecuteScalar(ConnectionStrings.ConnectionStrings.V4DB_READ, sql, pObjectGUID).ToString().Parse<int>();
                if (count > 0)
                    return objectType.Key;
            }
        }

This chunk should hit the domains table looking for domainguid and if count > 0 return ObjectType.Domain…look right? Only problem is, while it might seem somewhat clever, it’s like 2 dictionary objects, a couple strings, some nested loops, harder to read and debug than my first version, and about 10 more lines per check hehe…fun to experiment though and if this looks like to you then I guess it’s one more thing I can add to my brain 🙂


also found this how to fetch data from nested Dictionary in c#

  • 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-19T23:37:43+00:00Added an answer on May 19, 2026 at 11:37 pm

    You can definitely do it, although you’re currently missing a closing angle bracket and parentheses. It should be:

    var dictionary = new Dictionary<ObjectType, Dictionary<string, string>>().
    

    To add a given value you probably want something like:

    private void AddEntry(ObjectType type, string key, string value)
    {
        Dictionary<string, string> tmp;
        // Assume "dictionary" is the field
        if (!dictionary.TryGetValue(type, out tmp))
        {
            tmp = new Dictionary<string, string>();
            dictionary[type] = tmp;
        }
        tmp.Add(key, value);
    }
    

    If that doesn’t help, please show the code that you’ve tried and failed with – the database code in your question isn’t really relevant as far as I can tell, as it doesn’t try to use a nested dictionary.

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

Sidebar

Related Questions

I'm trying to create a shell (nothing serious just messing around) and want to
I am just messing around trying to make a game right now, but I
I'm just messing around with some C++ at the moment trying to make a
I am messing around with a basic CAAnimation example where Im just trying to
I'm just messing around trying to learn a little bit about parallel computing. If
I just started messing around with C#/.NET/mono and stuff, and I'm trying to make
I'm new to Cocoa Touch and I'm just messing around trying to get a
I'm just messing around with Javascript and JQuery and I've been trying to achieve
I'm just messing around with some HTML5, and I was trying to center a
I was just messing around with XNA and trying to get a simple player

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.