C# Math
C# Math
C# provides the Math class (in the System namespace) to perform common mathematical operations like rounding, power, square root, min/max, and trigonometry.
Basic Math Operations
Math Class (System.Math)
✔ Common Math Methods
| Method | Description | Example |
|---|---|---|
Math.Abs(x) | Absolute value | Math.Abs(-5) |
Math.Sqrt(x) | Square root | Math.Sqrt(16) |
Math.Pow(x, y) | Power | Math.Pow(2, 3) |
Math.Max(x, y) | Maximum value | Math.Max(5, 10) |
Math.Min(x, y) | Minimum value | Math.Min(5, 10) |
Math.Round(x) | Rounds value | Math.Round(5.6) |
Math.Floor(x) | Rounds down | Math.Floor(5.9) |
Math.Ceiling(x) | Rounds up | Math.Ceiling(5.1) |
Examples
Absolute Value
Square Root
Power
Min & Max
Rounding Numbers
Math Constants
Random Numbers
Trigonometric Functions
Summary
✔ Math class provides built-in math functions
✔ Supports rounding, power, root, min/max
✔ Includes constants like PI
✔ Random class generates random numbers
