I was unit testing in C#, and I found the following code gives an overflow exception:
using System;
public class Program
{
public static void Main()
{
int i = 0;
Console.WriteLine(new float[i - 1]);
// System.OverflowException: Arithmetic operation resulted in an overflow.
}
}
https://dotnetfiddle.net/clbgZ3
However, if you explicitly attempt to initialize a negative array, you get the following error:
Console.WriteLine(new float[-1]);
// Compilation error: Cannot create an array with a negative size
Why does initializing a negatively-sized array cause an overflow exception, and not a different type of error?