W
Whomsoever
Guest
I have a dictionary
Dictionary<int, List<int>> selections = new Dictionary<int, List<int>>();
which currently holds four keys, each of which corresponds to a list of integers (the lists vary in length from 3 to 6 items).
The problem arises when I try to retrieve the values from the lists as it only prints out one of the lists 4 times :
foreach (KeyValuePair<int, List<int>> item in selections.ToList())
{
List<int> choices = new List<int>();
int gameNo = item.Key;
choices = item.Value;
Console.Write($"Game : {gameNo} Selections : ");
for (int j = 0; j < choices.Count; j++)
{
Console.Write($"{choices[j]} ");
}
Console.WriteLine();
}
results in :
Game : 0 Selections : 6 11 17 19 27 30
Game : 1 Selections : 6 11 17 19 27 30
Game : 2 Selections : 6 11 17 19 27 30
Game : 3 Selections : 6 11 17 19 27 30
The dictionary definitely holds lists containing different elements prior to trying to extract the data. Any suggestions would be appreciated. Thank you
Continue reading...
Dictionary<int, List<int>> selections = new Dictionary<int, List<int>>();
which currently holds four keys, each of which corresponds to a list of integers (the lists vary in length from 3 to 6 items).
The problem arises when I try to retrieve the values from the lists as it only prints out one of the lists 4 times :
foreach (KeyValuePair<int, List<int>> item in selections.ToList())
{
List<int> choices = new List<int>();
int gameNo = item.Key;
choices = item.Value;
Console.Write($"Game : {gameNo} Selections : ");
for (int j = 0; j < choices.Count; j++)
{
Console.Write($"{choices[j]} ");
}
Console.WriteLine();
}
results in :
Game : 0 Selections : 6 11 17 19 27 30
Game : 1 Selections : 6 11 17 19 27 30
Game : 2 Selections : 6 11 17 19 27 30
Game : 3 Selections : 6 11 17 19 27 30
The dictionary definitely holds lists containing different elements prior to trying to extract the data. Any suggestions would be appreciated. Thank you
Continue reading...