Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda