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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:28:02+00:00 2026-05-30T03:28:02+00:00

Hi all I am having a requirement where I have to assign multiple keys

  • 0

Hi all I am having a requirement where I have to assign multiple keys and for that multiple keys I have to assign multiple values

My requirement is as follows. I am having EmpID, PayYr and PayID for each employee.

Assume I get my data as follows:

EmpID  1000    1000  1000   1000
PayYr  2011    2011  2011   2012
PayID    1      2     3      1

I would like to have my dictionary so that the dictionary with key value result is as follows:

1000 - 2011 - 1,2,3
1000 - 2012 - 1

I tried some thing as follows

public struct Tuple<T1, T2>
{
    public readonly T1 Item1;
    public readonly T2 Item2;

    public Tuple(T1 item1, T2 item2)
    {
        Item1 = item1;
        Item2 = item2;
    }
}

Sample code

for (int empcnt = 0; empcnt < iEmpID.Length; empcnt++)
    {
        for (int yrcnt = 0; yrcnt < ipayYear.Length; yrcnt++)
        {

            List<int> lst1 = new List<int>();
            var key1 = new Tuple<int, int>(iEmpID[empcnt], ipayYear[yrcnt]);
            if (!dictAddValues.ContainsKey(key1))
            {
                dictAddValues.Add(key1, lst1);
                lst1.Add(lst[yrcnt]);
            }
        }

    }

But I am not getting my result as i required so can any one help me.

  • 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-30T03:28:04+00:00Added an answer on May 30, 2026 at 3:28 am

    Personally, I’d probably use a Dictionary of Dictionaries, e.g. IDictionary<int, IDictionary<int, IList<int>>>. Not I am not entirely sure how you intend to access or facilitate this data; that will have a large impact on how efficient my suggestion is. On the upside, it would allow you to — relatively easily — access data, if and only if you access it in the order you set up your dictionaries.
    (On second thought, simply the type declaration itself is so ugly and meaningless, you might want to skip what I said above.)

    If you are accessing fields rather randomly, maybe a simple denormalized ICollection<Tuple<int, int, int>> (or equivalent) will have to do the trick, with aggregation in other parts of your application as needed. LINQ can help here a lot, especially its aggregation, grouping, and lookup features.

    Update: Hopefully this clarifies it:

    var outerDictionary = new Dictionary<int, Dictionary<int, List<int>>>();
    
    /* fill initial values
     * assuming that you get your data row by row from an ADO.NET data source, EF, or something similar. */
    foreach (var row in rows) {
        var employeeId = (int) row["EmpID"];
        var payYear = (int) row["PayYr"];
        var payId = (int) row["PayID"];
    
    
        Dictionary<int, int> innerDictionary;
        if (!outerDictionary.TryGet(employeeId, out innerDictionary)) {
            innerDictionary = new Dictionary<int, int>();
            outerDictionary.Add(employeeId, innerDictionary);
        }
    
        List<int> list;
        if (!innerDictionary.TryGet(payYear)) {
            list = new List<int>();
            innerDictionary.Add(payYear, list);
        }
    
        list.Add(payId);
    }
    
    /* now use it, e.g.: */
    var data = outerDictionary[1000][2011]; // returns a list with { 1, 2, 3 }
    

    Take it with a grain of salt though; see comment.

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

Sidebar

Related Questions

Hi all I am having a requirement like selecting multiple values and then to
I was having one requirement that is I have to write a high performance
I have 3 select boxes and all are having same value (clones) & created
I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates
I have one scenario where I need to select all files having aliencoders.numeric-digits like
Hi all I am having some problems that I think can be attributed to
All, I have a requirement to hide my EF implementation behind a Repository. My
I have a requirement for compiling large number of projects (some of them having
We have a requirement that has had me skimming the web for quite sometime
I'm having trouble finding a formula that explains the size requirement of my data

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.