Maximum length of byte[]?

后端 未结 4 794
孤独总比滥情好
孤独总比滥情好 2020-12-09 09:04

I\'m trying to create an array of bytes whose length is UInt32.MaxValue. This array is essentially a small(ish) in-memory database:



        
4条回答
  •  天命终不由人
    2020-12-09 09:38

    On .NET 4.5 The maximum instantiatable length of a byte array is: 2147483591, or 56 less than int.MaxValue. Found via:

    for (int i = int.MaxValue; i > 0; i--)
    {
        try
        {
            byte[] b = new byte[i];
            Console.Out.WriteLine("MaxValue: " + i);
            Environment.Exit(0);
        }
        catch (Exception ignored)
        {}
    }
    

提交回复
热议问题