I encountered this error with more complex model, but it's a behavior of the List
object:
List<int> numbers= new List<int>();
numbers[0] = 12; //The error occurs here
Console.WriteLine(numbers[0]);
The error is:
Index was out of range. Must be non-negative and less than the size of the collection.
edit
I know about Add()
and Insert()
, but I'm wondering why this odd error happens.