mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-05 06:15:24 +00:00
Initial commit
This commit is contained in:
parent
ca7684985d
commit
49bdd4dda1
60 changed files with 1527 additions and 30 deletions
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Console" Static="true" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
28
vs4win/Chapter03/CheckingForOverflow/Program.cs
Normal file
28
vs4win/Chapter03/CheckingForOverflow/Program.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue