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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:27+00:00 2026-05-25T18:09:27+00:00

I am starting to do a little development in C#, and I am stuck

  • 0

I am starting to do a little development in C#, and I am stuck with a problem here. Usually I develop in Python where stuff like this is being implemented easily (at least for me), but I have no idea how to do that in C#:

I want to create a dictionary containing a list of dictionaries like the following using Generic Collections:

{ "alfred",  [ {"age", 20.0}, {"height_cm", 180.1} ],
  "barbara", [ {"age", 18.5}, {"height_cm", 167.3} ],
  "chris",   [ {"age", 39.0}, {"height_cm", 179.0} ]
}

I started with the following:

using System.Collections.Generic;
Dictionary<String, Dictionary<String, double>[]> persons;

But then I’d like to insert the three records from above at once into persons. I am stuck with syntax errors all the way.

Anyone have a solution for me?

Edit:

Thank you all – I didn’t expect to receive so many well thought answers in such a short time! You are great!

  • 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-25T18:09:28+00:00Added an answer on May 25, 2026 at 6:09 pm

    You could use dictionary initializes. Not as elegant as Python, but could live with:

    var persons = new Dictionary<string, Dictionary<string, double>>
    {
        { "alfred", new Dictionary<string, double> { { "age", 20.0 }, { "height_cm", 180.1 } } },
        { "barbara", new Dictionary<string, double> { { "age", 18.5 }, { "height_cm", 167.3 } } },
        { "chris", new Dictionary<string, double> { { "age", 39.0 }, { "height_cm", 179.0 } } }
    };
    

    And then:

    persons["alfred"]["age"];
    

    Also notice that you need Dictionary<string, Dictionary<string, double>> for this structure and not Dictionary<string, Dictionary<string, double>[]>.

    Also working with such structure could be a little PITA and harm readability and compile-time type safety of the code.

    In .NET it is preferred to work with strongly typed objects, like this:

    public class Person
    {
        public double Age { get; set; }
        public string Name { get; set; }
        public double HeightCm { get; set; }
    }
    

    and then:

    var persons = new[]
    {
        new Person { Name = "alfred", Age = 20.0, HeightCm = 180.1 },
        new Person { Name = "barbara", Age = 18.5, HeightCm = 180.1 },
        new Person { Name = "chris", Age = 39.0, HeightCm = 179.0 },
    };
    

    and then you could use LINQ to fetch whatever information you need:

    double barbarasAge = 
        (from p in persons
         where p.Name == "barbara"
         select p.Age).First();
    

    To be noted of course that using collections would not be as fast as a hashtable lookup but depending on your needs in terms of performance you could also live with that.

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

Sidebar

Related Questions

OK, we're just starting our Sharepoint development, and I'm a little stuck on one
Okay, this is starting to drive me a little bit nuts. I've tried several
This little issue is starting to do my head in, I have read around
I'm struggling with a little problem and starting to arrive at the conclusion it's
Was looking to write a little web crawler in python. I was starting to
I'm starting a little RTS game with SDL and here are some questions: I
I'm starting to go a little crazy with this one. I have an iphone
It's been a little while since I did C++ development professionally and I'd like
I'm starting out with force.com development, and I'm currently a little hazy about what
I'm just starting with web frameworks and web development (I work only a little

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.