Math class in c#

Math class in c#

 

In this article, how to use c# math class. The C# Math class has many methods that allow you to perform mathematical operations.

 

Some example is given below-

Math.Round()

using System;

namespace usingcsharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Math.Round(100.61));
     }
  }
}

 

Math.Abs(x)

 

using System;

namespace usingcsharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Math.Abs(-5.12));  
     }
  }
}

 

Math.Sqrt(x)

using System;

namespace usingcsharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Math.Sqrt(100));  
     }
  }
}

 

Math.Min(x,y)

 

 

using System;

namespace usingcharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Math.Min(20, 100));  
     }
  }
}

 

Math.Max(x,y)

 

 

using System;

namespace usingcsharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Math.Max(6, 20));  
     }
  }
}

 

2021-10-03