Line data Source code
1 : namespace CalculatorLibrary {
2 :
3 : /// <summary>
4 : /// Performs basic arithmetic operations on integers.
5 : /// </summary>
6 : /// <remarks>
7 : /// This is the sample class the template ships with. When you start your own project, replace it
8 : /// (and <see cref="CalculatorCli"/>) with your own domain classes — see
9 : /// <c>docs/guide/from-topic-to-project.en.md</c> for the step-by-step walkthrough.
10 : /// </remarks>
11 : public class Calculator {
12 : /// <summary>Adds two integers.</summary>
13 : /// <param name="a">The first addend.</param>
14 : /// <param name="b">The second addend.</param>
15 : /// <returns>The sum of <paramref name="a"/> and <paramref name="b"/>.</returns>
16 10 : public int Add(int a, int b) {
17 10 : return a + b;
18 : }
19 :
20 : /// <summary>Subtracts one integer from another.</summary>
21 : /// <param name="a">The value to subtract from.</param>
22 : /// <param name="b">The value to subtract.</param>
23 : /// <returns>The result of <paramref name="a"/> minus <paramref name="b"/>.</returns>
24 6 : public int Subtract(int a, int b) {
25 6 : return a - b;
26 : }
27 :
28 : /// <summary>Multiplies two integers.</summary>
29 : /// <param name="a">The first factor.</param>
30 : /// <param name="b">The second factor.</param>
31 : /// <returns>The product of <paramref name="a"/> and <paramref name="b"/>.</returns>
32 6 : public int Multiply(int a, int b) {
33 6 : return a * b;
34 : }
35 :
36 : /// <summary>Divides one integer by another using integer (truncating) division.</summary>
37 : /// <param name="a">The dividend.</param>
38 : /// <param name="b">The divisor.</param>
39 : /// <returns>The integer quotient of <paramref name="a"/> divided by <paramref name="b"/>.</returns>
40 : /// <exception cref="DivideByZeroException">Thrown when <paramref name="b"/> is zero.</exception>
41 10 : public int Divide(int a, int b) {
42 10 : if (b == 0) {
43 2 : throw new DivideByZeroException();
44 : }
45 :
46 8 : return a / b;
47 : }
48 : }
49 : }
|