When working with arithmetic operators in c# I noticed that there is no compile time error but an obvious runtime one. Is there any way to notice this kind of overflow exceptions as a compile time error when converting integral types to each other?
static void Main(string[] args)
{
byte[] myArray = new byte[10];
for (byte counter = 0; counter < myArray.Length; counter++)
{
myArray[counter] = Convert.ToByte(counter + 300);
}
foreach (int member in myArray)
{
Console.WriteLine(member);
}
}
Obviously when you run this code because it'll try to store a value over 300 in a byte, you'll get an OverflowException due to its 256 limitation.