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

MethodDescriptionExample
Math.Abs(x)Absolute valueMath.Abs(-5)
Math.Sqrt(x)Square rootMath.Sqrt(16)
Math.Pow(x, y)PowerMath.Pow(2, 3)
Math.Max(x, y)Maximum valueMath.Max(5, 10)
Math.Min(x, y)Minimum valueMath.Min(5, 10)
Math.Round(x)Rounds valueMath.Round(5.6)
Math.Floor(x)Rounds downMath.Floor(5.9)
Math.Ceiling(x)Rounds upMath.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

You may also like...