I have two lists and I want to copy data from one to another and I get this error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Here’s my code:
static IList<Common.Data.Driver> Stt_driverList = new List<Common.Data.Driver>();
List<Common.Data.Driver> driverList = new List<Common.Data.Driver>();
for (int i = 0; i < driverList.Count; i++)
{
//Fill in The Static Driver List
Stt_driverList[i] = driverList[i];
}
Stt_driverListdoes not contain any items when you start looping, so you can’t refer to elements by index. Try using theAddmethod instead: