Skip to content

Commit 3bc2fa6

Browse files
Update sample
1 parent 4794e53 commit 3bc2fa6

File tree

1 file changed

+9
-47
lines changed

1 file changed

+9
-47
lines changed

SampleProject/Program.cs

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,21 @@
1-
Calculator calculator = new();
2-
1+

32
try
43
{
5-
Console.Write("Add integers\n");
6-
7-
Console.Write("Left-hand side: ");
8-
var lhsStr = Console.ReadLine();
9-
10-
var lhs = int.Parse(lhsStr!);
11-
12-
Console.Write("Right-hand side: ");
13-
var rhsStr = Console.ReadLine();
4+
var result = AddStringsAsNumbers("1", "b");
145

15-
var rhs = int.Parse(rhsStr!);
16-
17-
try
18-
{
19-
var sum = calculator.Add(lhs, rhs);
20-
21-
Console.WriteLine($"Sum is: {sum}");
22-
}
23-
catch (OverflowException e)
24-
{
25-
Console.WriteLine($"The sum exceeds the bounds of which min is {int.MinValue} and and max is {int.MaxValue}");
26-
}
27-
}
28-
catch (OverflowException)
29-
{
30-
Console.WriteLine($"Specified number must be between {int.MinValue} and {int.MaxValue}");
6+
Console.WriteLine(result);
317
}
328
catch (FormatException)
339
{
34-
Console.WriteLine("Expected integer number");
35-
}
36-
catch (ArgumentOutOfRangeException)
37-
{
38-
Console.WriteLine("Argument is out of range");
10+
3911
}
40-
catch
12+
catch (OverflowException)
4113
{
42-
Console.WriteLine("Out of memory");
14+
4315
}
4416

45-
public class Calculator
17+
[Throws(typeof(FormatException), typeof(OverflowException))]
18+
static int AddStringsAsNumbers(string a, string b)
4619
{
47-
/// <summary>
48-
/// Add numbers
49-
/// </summary>
50-
/// <param name="a">Left-hand side</param>
51-
/// <param name="b">Right-hand side</param>
52-
/// <returns>The sum of a and b.</returns>
53-
/// <exception cref="System.OverflowException">The result exceeds the bounds.</exception>
54-
[Throws(typeof(OverflowException))]
55-
public int Add(int a, int b)
56-
{
57-
return a + b;
58-
}
20+
return int.Parse(a) + int.Parse(b);
5921
}

0 commit comments

Comments
 (0)