Calculator Class
Definition
Provides a set of static methods for generic arithmetic assignment operations.
public static class Calculator
- Inheritance
-
objectCalculator
Examples
The following example demonstrates how to use the Calculator class to perform basic arithmetic and bitwise operations. Each method call prints the computed result to the console.
using System;
using Cuemon;
namespace MyApp.Arithmetic;
public class CalculatorExample
{
public void Demonstrate()
{
int sum = Calculator.Add(10, 20);
Console.WriteLine(sum); // 30
int difference = Calculator.Subtract(20, 5);
Console.WriteLine(difference); // 15
int product = Calculator.Multiply(4, 5);
Console.WriteLine(product); // 20
int quotient = Calculator.Divide(20, 4);
Console.WriteLine(quotient); // 5
int remainder = Calculator.Remainder(10, 3);
Console.WriteLine(remainder); // 1
int bitwiseAnd = Calculator.And(0b1100, 0b1010);
Console.WriteLine(bitwiseAnd); // 8 (0b1000)
}
}
Methods
| Name | Description |
|---|---|
| Add<T>(T, T) | Performs a binary addition of the two specified values. |
| And<T>(T, T) | Performs a a bitwise logical conjunction (AND) operation of the two specified values. |
| Assign<T>(T, T) | Performs an assignment of the right-hand operand to the left-hand operand. |
| Calculate<T>(T, AssignmentOperator, T) | Performs a calculation following the |
| Divide<T>(T, T) | Performs a binary division of the two specified values. |
| ExclusiveOr<T>(T, T) | Performs a bitwise exclusive or (XOR) operation of the two specified values. |
| LeftShift<T>(T, T) | Performs an arithmetic left shift (<<) operation. |
| Multiply<T>(T, T) | Performs a binary multiplication of the two specified values. |
| Or<T>(T, T) | Performs a bitwise logical disjunction (OR) operation of the two specified values. |
| Remainder<T>(T, T) | Performs a binary division of the two specified values and computes the remainder hereof. |
| RightShift<T>(T, T) | Performs an arithmetic right shift (>>) operation. |
| Subtract<T>(T, T) | Performs a binary subtraction of the two specified values. |
| ValidAsNumericOperand<T>() | Validates if the specified |