我一直在使用ILSpy查看.NET库,并List<T>在System.Collections.Generic命名空间中遇到了类定义.我看到该类使用类似这样的方法:
// 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++;
}
Run Code Online (Sandbox Code Playgroud)
所以,类的Clear()方法List<T>实际上使用Array.Clear方法.我已经看到许多其他List<T>方法在体内使用Array的东西.
这是否意味着List<T>实际上是一个秘密数组或List只使用了一些Array方法?
我知道列表是类型安全的,不需要装箱/拆箱,但这让我有点困惑.