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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:48:07+00:00 2026-06-15T10:48:07+00:00

I have the following code : List<Dictionary<string, string>> allMonthsList = new List<Dictionary<string, string>>(); while

  • 0

I have the following code :

List<Dictionary<string, string>> allMonthsList = new List<Dictionary<string, string>>();
while (getAllMonthsReader.Read()) {
    Dictionary<string, string> month = new Dictionary<string, string>();
    month.Add(getAllMonthsReader["year"].ToString(),
    getAllMonthsReader["month"].ToString());
    allMonthsList.Add(month);
}
getAllMonthsReader.Close();

Now I’m trying to loop through all of the months, like this :

foreach (Dictionary<string, string> allMonths in allMonthsList)

How do I access the key values? Am I doing something wrong?

  • 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-15T10:48:08+00:00Added an answer on June 15, 2026 at 10:48 am
    foreach (Dictionary<string, string> allMonths in allMonthsList)
    {
        foreach(KeyValuePair<string, string> kvp in allMonths)
         {
             string year = kvp.Key;
             string month = kvp.Value;
         }
    }
    

    BTW year usually has more than one month. Looks like you need a lookup here, or Dictionary<string, List<string>> for storing all months of year.

    Explanation generic dictionary Dictionary<TKey, TValue> implements IEnumerable interface, which returns an enumerator that iterates through the collection. From msdn:

    For purposes of enumeration, each item in the dictionary is treated as
    a KeyValuePair<TKey, TValue> structure representing a value and its
    key. The order in which the items are returned is undefined.

    The foreach statement of the C# language requires the type of each element in the collection.
    Since the Dictionary<TKey, TValue> is a collection of keys and values,
    the element type is not the type of the key or the type of the value.
    Instead, the element type is a KeyValuePair<TKey, TValue> of the key
    type and the value type.

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

Sidebar

Related Questions

I have the following code snippet: Dictionary<int, List<string>> likeListDict = new Dictionary<int, List<string>>(); List<string>
I have the following code to populate a DropDownList var list = new Dictionary<string,
I have the following code new Dictionary<string,IEnumerable<Control>>() { { view1, new Control[] { contents,
I have written the following C# code: _locationsByRegion = new Dictionary<string, IEnumerable<string>>(); foreach (string
I have the following code in C# that returns a Dictionary<string, List<Discount>> . static
I have the following code: List<int> intList = new ArrayList<int>(); for (int index =
I have the following code: List<T> list = new List<T>(); IEnumerable<T> query1 = ...
I have the following code: List<HtmlMeta> metas = new List<HtmlMeta>(); foreach (Control c in
I have the following C# code: List<int[,]> l1 = new List<int[,]>(); l1[0] = new
I have the following code: SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); now

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.