Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda