I am getting an index out of range error, when I initialize the TValue to 10. So the elements should exist.
Code
if (!sportsDictionary.ContainsKey(sports.Team))
{
sportsDictionary.Add(sports.Team, new List(10));
}
else
{
sportsDictionary[sports.Team][Team.sportsId] = sports;
//Error: index out of range above
}
Joginder BangerRank #360 · 7K reputationPosted Jul 30, 2016, 8:58 PM EDT
David SmithRank #999 · 2K reputationPosted Jul 31, 2016, 12:24 AM EDT
David SmithRank #999 · 2K reputationPosted Jul 31, 2016, 12:25 AM EDT
{
if (sportsDictionary[sportsObject.Team].Count < sportsObject.Index)
{
int resize = sportsObject.Index - sportsDictionary[Sports.Team].Count;
for (int i = 0; i <= resize; i++)
{
sportsDictionary[Sports.Team].Add(new SportsObject());
}
}
sportsDictionary[Sports.Team].Insert(waypoint.Index, sportsObject);
}