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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:52:13+00:00 2026-05-31T19:52:13+00:00

I have written a code for adding multiple keys for a dictionary for that

  • 0

I have written a code for adding multiple keys for a dictionary for that I defined my dictionary as follows and added the keys and values

Dictionary<int, Dictionary<int, List<int>>> outerDictionary = new Dictionary<int, Dictionary<int, List<int>>>();

Now I would like to loop through each keys in-order to get the required items can any one tell how can I loop through for each key value as per my dictionary

My code

Dictionary<int, Dictionary<int, List<int>>> outerDictionary = new Dictionary<int, Dictionary<int, List<int>>>();
Dictionary<int, List<int>> innerDictionary;

    ArrayList arrPayPeriodID = new ArrayList();
    ArrayList arrPayYear = new ArrayList();
    ArrayList arrEmpID = new ArrayList();

    int[] ipayYear = new int[] { };
    int[] iPayPeriodID = new int[] { };
    int[] iEmpID = new int[] { };

    int ipayYr = 2011;
    int ipayYr1 = 2011;
    int ipayYr2 = 2012;
    int ipayYr3 = 2012;

    int PayPeriodID = 1;
    int payperiodid1 = 2;
    int payperiodid2 = 2;
    int payperiodid3 = 2;

    int EmpID = 1;
    int EmpID1 = 1;
    int EmpID2 = 1;
    int EmpID3 = 1;

    arrEmpID.Add(EmpID);
    arrEmpID.Add(EmpID1);
    arrEmpID.Add(EmpID2);
    arrEmpID.Add(EmpID3);

    arrPayPeriodID.Add(PayPeriodID);
    arrPayPeriodID.Add(payperiodid2);
    arrPayPeriodID.Add(payperiodid3);
    arrPayPeriodID.Add(payperiodid1);

    arrPayYear.Add(ipayYr);
    arrPayYear.Add(ipayYr1);
    arrPayYear.Add(ipayYr2);
    arrPayYear.Add(ipayYr3);

    iEmpID = (int[])arrEmpID.ToArray(typeof(int));

    iPayPeriodID = (int[])arrPayPeriodID.ToArray(typeof(int));

    ipayYear = (int[])arrPayYear.ToArray(typeof(int));


    DataTable table = GetTable(iEmpID, ipayYear, iPayPeriodID);
    DataRow row = table.Rows[0];

    for (int i = 0; i < table.Rows.Count; i++)
    {
        DataRow row1 = table.Rows[i];
        var employeeId = (int)row1["EmpID"];
        var payYear = (int)row1["Year"];
        var payId = (int)row1["PayID"];



        if (!outerDictionary.TryGetValue(employeeId, out innerDictionary))
        {
            innerDictionary = new Dictionary<int, List<int>>();
            outerDictionary.Add(employeeId, innerDictionary);
        }
        List<int> list;
        if (!innerDictionary.TryGetValue(payYear, out list))
        {
            list = new List<int>();
            innerDictionary.Add(payYear, list);
        }

        list.Add(payId);
    }

static DataTable GetTable(int[] empID, int[] payYr, int[] payID)
{

    // Here we create a DataTable with four columns.
    DataTable table = new DataTable();
    table.Columns.Add("EmpID", typeof(int));
    table.Columns.Add("Year", typeof(int));
    table.Columns.Add("PayID", typeof(int));

    // Here we add five DataRows.
    for (int i = 0; i < empID.Length; i++)
    {
        table.Rows.Add(empID[i], payYr[i], payID[i]);
    }
    return table;
}
  • 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-31T19:52:14+00:00Added an answer on May 31, 2026 at 7:52 pm
    Dictionary<int, Dictionary<int, List<int>>> outer = new Dictionary<int, Dictionary<int, List<int>>>();
    foreach(var outerKey in outer.Keys.OrderBy(x => x))
    {
        foreach(var innerKey in outer[outerKey].Keys.OrderBy(x => x))
            Console.WriteLine(outer[outerKey][innerKey]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a piece of code in C#. That is, dynamically adding TextBox
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written code to perform a function that could take a while to
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written the code below for adding products to a basket, then outputting
I have written a code in java using swing.So that i will have a
I have written a code in java using swing, so that I will have
I have written a control in C# that derives from System.Windows.Forms.Control. I have added
I have written code in Java to access web cam,and to save image... I

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.