Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math Sqrt() method returns the square root of the given number. In special cases it returns the following:

  • If the argument is NaN or less than zero, then method returns NaN.
  • If the argument is PositiveInfinity, the method returns the same as the argument.

Syntax

public static float Sqrt (float arg);

Parameters

arg Specify the number whose square root to be found.

Return Value

Returns the square root of the specified number.

Example:

In the below example, Sqrt() method is used to find out the square root of the given number.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine(Math.Sqrt(25)); 
    Console.WriteLine(Math.Sqrt(30)); 
    Console.WriteLine(Math.Sqrt(35.5)); 
    Console.WriteLine(Math.Sqrt(-25));
  }
}

The output of the above code will be:

5
5.477225575051661
5.958187643906492
NaN

❮ C# Math Methods