列表默认容量容量、列表

2023-09-03 00:02:18 作者:梦里梦你梦离

什么是列表的默认容量?

What is the default capacity of a List?

推荐答案

为什么你不试一试呢?

Console.WriteLine("Default capacity of a List: " + new List<int>().Capacity);

这个答案将工作在.NET中有列出所有版本。在我的版本,它正好是0。

This answer will work on all versions of .NET that have List. On my version, it happens to be 0.