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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:08:48+00:00 2026-06-07T21:08:48+00:00

How do I flatten a nested dictionary into a list of some objects (

  • 0

How do I flatten a nested dictionary into a list of some objects (SomeObject in the following example) which should hold keys of those dictionaries?

For example: let’s have a dictionary of the following type

var nestedDictionary = new Dictionary<int, Dictionary<int, string>>();

then, let’s have this class

public class SomeObject
{
   public int var1;
   public int var2;
   public string someStringVar;
}

How do I convert nestedDictionary to a List<SomeObject> where var1 is the key of the outer dictionary, var2 is the key of the inner dictionary and someStringVar is the string value of the inner dictionary?

Essentially, how do I transfer this:

nestedDict[0][0] = "foo";
nestedDict[0][1] = "bar";
nestedDict[0][2] = "foo1";
nestedDict[1][0] = "bar1";
nestedDict[1][1] = "foo2";
nestedDict[1][2] = "bar2";

to this (in pseudo C# just to visualize it)

objList[0] = SomeObject { var1 = 0, var2 = 0, someStringVar = "foo" }
objList[1] = SomeObject { var1 = 0, var2 = 1, someStringVar = "bar" }
objList[2] = SomeObject { var1 = 0, var2 = 2, someStringVar = "foo1" }
objList[3] = SomeObject { var1 = 1, var2 = 0, someStringVar = "bar1" }
objList[4] = SomeObject { var1 = 1, var2 = 1, someStringVar = "foo2" }
objList[5] = SomeObject { var1 = 1, var2 = 2, someStringVar = "bar2" }

using LINQ?

  • 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-06-07T21:08:50+00:00Added an answer on June 7, 2026 at 9:08 pm

    This should work:

    var flattened =
    from kvpOuter in nestedDictionary
    from kvpInner in kvpOuter.Value
    select new SomeObject()
    {
        var1 = kvpOuter.Key,
        var2 = kvpInner.Key,
        someStringVar = kvpInner.Value
    };
    var list = flattened.ToList(); // if you need a list...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to flatten objects into nested dicts of the object's properties. The objects
How to convert the nested hierarchical object to flatten objects by using LINQ? I
I am trying to flatten nested objects like this: public class Book { public
Possible Duplicate: Flatten (an irregular) list of lists in Python I have the following
I'm using ValueInjecter to flatten/unflatten view models into domain objects created by Entity Framework
How can I flatten a two dimensional array into one dimensional array? For example:
I would like to flatten arbitrary deeply nested collections/structures of elements of some type
I'm doing an exercise to flatten nested lists. The code works in console but
Anything like flatten, count-atoms, etc. over nested lists would do fine. BTW, I'm not
I have a heavily nested XML document that I need to load into my

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.