byte[] b = new byte[int.MaxValue]; 这句会出错,数组对象最大长度是多少?
应该是内存不够,32 位操作系统无法分配2G内存给数组。
报的什么错?是不是内存不够了?
是的,数组没有最大限制,主要看你机器内存能承受多大
byte[] b = new byte[int.MaxValue-56]; //windows 7 64位,4G内存
byte[] b = new byte[int.MaxValue/2]; //windows 2003 sp2 32位,4G内存
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
{
if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue)
throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue)
throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
if (length > Int32.MaxValue || length < Int32.MinValue)
throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
Array.Copy(sourceArray, (int) sourceIndex, destinationArray, (int) destinationIndex, (int) length);
}
这是数组的源码,你看一下,详细的可以看我的随笔,有什么问题再问我