The System.Collections.Generic as most of C# developers knows, contains the List class. The class exposes the Add method, which is implemented as follows:
[__DynamicallyInvokable]
public void Add(T item)
{
if (this._size == this._items.Length)
{
this.EnsureCapacity(this._size + 1);
}
T[] arg_36_0 = this._items;
int size = this._size;
this._size = size + 1;
arg_36_0[size] = item;
this._version++;
}
I am trying to understand how this works... I have a local array of type T, called "_items", there are also the "_size" and "_version" variables. When a new item is added, a new array of type T is created and called "arg_36_0", the private array is assigned to the new one. size is copied; then the local size is incremented, and to the newly created array we are assigning the passed new item. So after this function finishes, the local "arg_36_0" array will be removed, the item is never assigned to the actual array (called "_items"). What am I missing here? :)