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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:58:15+00:00 2026-06-08T21:58:15+00:00

Does somebody know how to convert an arraylist to a list of dictionaries? What

  • 0

Does somebody know how to convert an arraylist to a list of dictionaries?
What do I have? I have an ArrayList (list) with a lot of strings:

            foreach (string s in list)
            {
                Console.WriteLine(s);
            }

output:
klaus
male
spain
lissy
female
england
peter
male
usa
...

As we see there is an order. The first entry is a NAME, second GENDER, third COUNTRY and then again NAME, GENDER… and so on.

Now for clarity I would like to store these attributes in a List of Dictionaries. Every List entry should be 1 Dictionary with these 3 Attributes. Is this a good idea? Whats the easiest way? I just search something to store this list in a better looking collection that is later easiert to handle. I have this:

    List<Dictionary<string, string>> dlist = new List<Dictionary<string, string>>();
    const int separate = 3;

    foreach (string s in list)
    {
        //add list entries to dlist?
    }
  • 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-08T21:58:17+00:00Added an answer on June 8, 2026 at 9:58 pm

    No it’s not a good idea. Define a class.

    At least something like this:

    class Person
    {
        public string Name { get; set; }
        public string Gender { get; set; }
        public string Country { get; set; }
    }
    

    Even better would be to use an enum for Gender, and possibly a class (built-in or custom) for the country.

    Anyway, to populate a collection with the above class, you’d use something like:

    List<Person> result = new List<Person>();
    
    for (int i = 0; i < list.Count; i += 3) { 
        result.Add(
            new Person { Name = list[i], Gender = list[i+1], Country = list[i+2] }); 
    } 
    

    Note that this loop lacks error checking on the count of items in the list, which should be a multiple of three.

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

Sidebar

Related Questions

Does somebody know a script that is able to convert a string to a
Does somebody know, how to set up Aptana, to have only one .metadata setting
Supposed I have a file with Perl-code: does somebody know, if there is a
Does somebody know how to use FFMPEG on Android to convert YUV420 frame to
Does somebody know why the output of this code is only : Message Sended
Does somebody know what is the memory overhead of a ConcurrentHashMap (compared to a
Does somebody know a module, which has a function that returns ( for example
I'm using Ruby on rails. Does somebody know how can I insert a javascript
does anybody know how to convert any kind of video format into flv using
Does somebody know a quick and easy explode() like function that can ignore splitter

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.