Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
c# Collection of Dictionary

how would I create and then access a collection of a (Sorted)Dictionary? It could be a Series<SortedDictionary<double, MyClass>> or a Dictionary<int, SortedDictionary<double, MyClass>> for example.

Series[0] = sortedDict;
Dict.Add(myInt, sortedDict);

For some reason, when doing it like this, the Dictionary is empty, when accessing values with a loop and the series seems to be empty as well.

for (int i = 0; i < Dict.Count; i++)
{
   SortedDictionary<double, MyClass> sortedDictPair = Dict.ElementAt(i).Value;
   foreach (var item in sortedDictPair)
   {
        Print(item.Key);
        MyClass myClass= item.Value;
        Print(myClass.classMember);
    }
}

SortedDictionary<double, MyClass> sortedDictPair = Series[0];
for (int j = 0; j < sortedDictPair.Count; j++)
    {
        MyClass myClass = sortedDictPair.ElementAt(j).Value;
        Print(myClass.classMember);
    }
 }

Is there something I am overseeing? Edit: when I let it print the sortedDict before aissgning it, it is full of entries.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Can you try them in two foreach loops?

Dictionary<int, SortedDictionary<double, MyClass>> dictionary = new Dictionary<int, SortedDictionary<double, MyClass>>()
    {
        { 1, new SortedDictionary<double,MyClass>(){ {2, new MyClass{ Score=1 } }, { 3, new MyClass { Score = 1 } } } },
        { 2, new SortedDictionary<double,MyClass>()}
    };
    foreach (var item1 in dictionary)
    {
        foreach (var item2 in item1.Value)
        {
            Console.WriteLine(item2.Key);
            MyClass myClass = item2.Value;
            Console.WriteLine(myClass.Score);
        }
    }

Check

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!