我可以向List添加多少个值?
例如:
List<string> Item = runtime data
Run Code Online (Sandbox Code Playgroud)
数据的大小不固定.它可能是10 000或超过1 000 000.我用谷歌搜索但没有找到确切的答案.
在读取大量文件时,使用C#时出现内存不足异常
我需要更改代码但是暂时可以增加堆大小(就像我在Java中一样)作为一个shaort术语修复?
考虑以下代码:
string value = new string('a', int.MaxValue);
Run Code Online (Sandbox Code Playgroud)
当我们运行该代码时发生OutOfMemoryException.Windows 8中的物理内存限制为128 GB.
那么为什么.Net会抛出OutOfMemoryException那些代码呢?
此代码也从不抛出OutOfMemoryException:
List<string> list = new List<string>();
for (int i = 0; i < 100000000000; i++)
{
list.Add(new string('a', 100 ));
}
Run Code Online (Sandbox Code Playgroud)
我在64位模式下运行它.