// sum should hold the value 350. However, we find the value 94!
Console.WriteLine("sum = {0}", sum);
}
If you were to view the output of this application, you might be surprised to find that sum con-
tains the value 94 (rather than the expected 350). The reason is simple. Given that a System.Byte can
hold a value only between 0 and 255 (inclusive, for a grand total of 256 slots), sum now contains the
overflow value (350 – 256 = 94). By default, if you take no corrective course of action, overflow/under-
flow conditions occur without error.
To handle overflow or underflow conditions in your application, you have two options. Your
first choice is to leverage your wits and programming skills to handle all overflow/underflow condi-
tions manually. Assuming you were indeed able to find each overflow condition in your program,
you could resolve the previous overflow error as follows:
Do'stlaringiz bilan baham: |