I am attempting to add a value to a list at a specific index, which according to everything I've read, should be do-able with List's Insert()
method.
Except I'm getting the exception "Index must be within the bounds of the List. Parameter name: index`
Here is my complete sample code.
class Program
{
static void Main(string[] args)
{
MyList myList = new MyList();
}
}
class MyList : List<int>
{
public MyList()
{
this.Capacity = 2;
this.Insert(1, 0);
}
}
Is the only option to change to a nullable list type and call .Add(null)
for each index and not use Insert()
?