Separate code blocks for each method (Sum, Subtract, Multiply, and Division) along with their respective main methods. This way, you can easily reference each specific implementation.
Sum Instance Method (No return, no parameter)
usingSystem;
classCalculator
{
publicvoidSum()
{
int a =10;
int b =5;
Console.WriteLine($"Sum: {a + b}");
}
}
classProgram
{
staticvoidMain(string[] args)
{
Calculator calc =newCalculator();
calc.Sum();
}
}
Sum Static Method (No return, no parameter)
usingSystem;
classCalculator
{
publicstaticvoidSum()
{
int a =10;
int b =5;
Console.WriteLine($"Sum: {a + b}");
}
}
classProgram
{
staticvoidMain(string[] args)
{
Calculator.Sum();
}
}
Subtract Instance Method (With parameter, no return)
usingSystem;
classCalculator
{
publicvoidSubtract(int a,int b)
{
Console.WriteLine($"Difference: {a - b}");
}
}
classProgram
{
staticvoidMain(string[] args)
{
Calculator calc =newCalculator();
calc.Subtract(20,7);
}
}
Subtract Static Method (With parameter, no return)
usingSystem;
classCalculator
{
publicstaticvoidSubtract(int a,int b)
{
Console.WriteLine($"Difference: {a - b}");
}
}
classProgram
{
staticvoidMain(string[] args)
{
Calculator.Subtract(20,7);
}
}
Multiply Instance Method (With parameter and return)
usingSystem;
classCalculator
{
publicintMultiply(int a,int b)
{
return a * b;
}
}
classProgram
{
staticvoidMain(string[] args)
{
Calculator calc =newCalculator();
int product = calc.Multiply(6,4);
Console.WriteLine($"Product: {product}");
}
}
Multiply Static Method (With parameter and return)
usingSystem;
classCalculator
{
publicstaticintMultiply(int a,int b)
{
return a * b;
}
}
classProgram
{
staticvoidMain(string[] args)
{
int product = Calculator.Multiply(6,4);
Console.WriteLine($"Product: {product}");
}
}
Division Instance Method (With return, no parameter)