System.Math.Sqrt Method

Returns the square root of a specified number.

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public static double Sqrt (double d)

Parameters

d
The number whose square root is to be found.

Returns

One of the values in the following table.

Zero or positive

The positive square root of d.

Negative

double.NaN

Equals double.NaN

double.NaN

Equals double.PositiveInfinity

double.PositiveInfinity

Remarks

Documentation for this section has not yet been entered.

Example

The following example demonstrates using the Math.Sqrt(double) method.

C# Example

using System;

public class MathSqrtExample
{

   public static void Main()
   {

      Double d1 = Math.Sqrt(16.0);
      Double d2 = Math.Sqrt(0.0);
      Double d3 = Math.Sqrt(-10.0);
      Console.WriteLine("Math.Sqrt(16.0) returns {0}", d1);
      Console.WriteLine("Math.Sqrt(0.0) returns {0}", d2);
      Console.WriteLine("Math.Sqrt(-10.0) returns {0}", d3);

   }

}

The output is

Math.Sqrt(16.0) returns 4
Math.Sqrt(0.0) returns 0
Math.Sqrt(-10.0) returns NaN

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0