David Smith

David Smith

  • NA
  • 2k
  • 0

Dictionary out of range

Jul 30 2016 9:51 PM

I am getting an index out of range error, when I initialize the TValue to 10. So the elements should exist.

 if (!sportsDictionary.ContainsKey(sports.Team))    
{
sportsDictionary.Add(sports.Team, new List<SportsObject>(10));
}
else
{
sportsDictionary[sports.Team][Team.sportsId] = sports;
//Error: index out of range above
}


Answers (3)