3
Answers

Dictionary out of range

David Smith

David Smith

8y
376
1

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)