# MathF.Sqrt() Method in C# with Examples

In C#, MathF.Sqrt(Single) is a MathF class(present in system namespace) method which is used to calculate the square root of the specified Single or float data type value.

Syntax: public static float Sqrt (float x);
Here, x is the number whose square root is to be calculated and type of this parameter is System.Single.

Return Type: This method returns the square root of x. If x is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. The return type of this method is System.Single.

Below are the examples to illustrate the use of the above-discussed method:
Example 1:

 `// C# program to demonstrate the ` `// MathF.Sqrt(Single) Method ` `using` `System; ` ` `  `class` `GFG { ` ` `  `    ``// Main Method ` `    ``public` `static` `void` `Main() ` `    ``{ ` ` `  `        ``// taking positive value ` `        ``float` `x = 78521F; ` ` `  `        ``// taking negative value ` `        ``float` `x1 = -7824F; ` ` `  `        ``// Input positive value ` `        ``// Output will be square ` `        ``// root of x ` `        ``Console.WriteLine(MathF.Sqrt(x)); ` ` `  `        ``// Input negative value, ` `        ``// Output will be NaN ` `        ``Console.Write(MathF.Sqrt(x1)); ` `    ``} ` `} `

Output:

```280.216
NaN
```

Example 2:

 `// C# program to demonstrate the MathF.Sqrt() ` `// method when the argument is positive ` `// or negative Zero ` `using` `System; ` ` `  `class` `GFG { ` ` `  `    ``// Main Method ` `    ``public` `static` `void` `Main() ` `    ``{ ` ` `  `        ``// taking positive zero  ` `        ``float` `x = 0f; ` `        ``Console.WriteLine(MathF.Sqrt(x)); ` ` `  `        ``// taking negative zero ` `        ``float` `y = -0f; ` `        ``Console.Write(MathF.Sqrt(y)); ` `    ``} ` `} `

Output:

```0
0
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.