I have been looking at .NET libraries using ILSpy and have come across List<T>
class definition in System.Collections.Generic
namespace. I see that the class uses methods like this one:
// System.Collections.Generic.List<T>
/// <summary>Removes all elements from the <see cref="T:System.Collections.Generic.List`1" />.</summary>
public void Clear()
{
if (this._size > 0)
{
Array.Clear(this._items, 0, this._size);
this._size = 0;
}
this._version++;
}
So, the Clear()
method of the List<T>
class actually uses Array.Clear
method. I have seen many other List<T>
methods that use Array stuff in the body.
Does this mean that List<T>
is actually an undercover Array or List only uses some part of Array methods?
I know lists are type safe and don't require boxing/unboxing but this has confused me a bit.
See Question&Answers more detail:os