mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2025-12-06 05:32:03 +01:00
29 lines
522 B
C#
29 lines
522 B
C#
try
|
|
{
|
|
checked
|
|
{
|
|
int x = int.MaxValue - 1;
|
|
WriteLine($"Initial value: {x}");
|
|
x++;
|
|
WriteLine($"After incrementing: {x}");
|
|
x++;
|
|
WriteLine($"After incrementing: {x}");
|
|
x++;
|
|
WriteLine($"After incrementing: {x}");
|
|
}
|
|
}
|
|
catch (OverflowException)
|
|
{
|
|
WriteLine("The code overflowed but I caught the exception.");
|
|
}
|
|
|
|
unchecked
|
|
{
|
|
int y = int.MaxValue + 1;
|
|
WriteLine($"Initial value: {y}");
|
|
y--;
|
|
WriteLine($"After decrementing: {y}");
|
|
y--;
|
|
WriteLine($"After decrementing: {y}");
|
|
}
|