C# provides a Math class in the System namespace that provides a wide range of mathematical functions. Here are some of the most commonly used methods in the Math class:
int a = -10;
int b = Math.Abs(a); // b = 10
double a = 3.14159;
double b = Math.Round(a); // b = 3
double a = 3.9;
double b = Math.Floor(a); // b = 3
double a = 3.1;
double b = Math.Ceiling(a); // b = 4
double a = 16;
double b = Math.Sqrt(a); // b = 4
double a = 2;
double b = Math.Pow(a, 3); // b = 8
int a = 10;
int b = 20;
int c = Math.Max(a, b); // c = 20
int a = 10;
int b = 20;
int c = Math.Min(a, b); // c = 10
These are just a few of the many functions provided by the Math class in C#. The exact function you need will depend on the specific program you’re writing.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.