I’m learning C# and I’m doing a task where I’m using a list of objects. I thought if I inserted a new object, with list.insert(index, object) at a position where it already is an object, the prevous object was replaced!?
But it seems that I have to remove it first with list.removeAt(index) before I can insert the new one, otherwise it was just added and the old left in the list. Is this correct or am I doing something wrong?
The Insert Method inserts a new item at the specified index, making space as needed:
If you want to replace an item at a specified index, you can use the list’s indexer:
See also: Indexers (C# Programming Guide)