Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以存储在 List 中的元素是否有限制?或者你可以一直添加元素直到你内存不足?
当前的实现无处不在- 为它的属性构造它的支持数组,List<T>作为一个索引器和它的所有内部操作 - 所以有一个当前理论上的项目最大值(或)。Int32 CountInt32.MaxValue2^31-12147483647
List<T>
Int32
Count
Int32.MaxValue
2^31-1
2147483647
但是 .NET 框架也有 2GB 的最大对象大小限制,因此您只能通过单字节项目列表(例如List<byte>或List<bool>.
List<byte>
List<bool>
在实践中,您可能会在达到这些限制之前耗尽连续内存。