![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MathF.Sqrt() Method in C# with Examples
The MathF.Sqrt() method in C# is used to compute the square root of the floating-point value.
Syntax
Following is the syntax −
public static float Sqrt (float val);
Above, Val is the number whose square root is to be computed.
Example
Let us now see an example to implement the MathF.Sqrt() method −
using System; public class Demo { public static void Main(){ float val1 = 36f; float val2 = float.NaN; Console.WriteLine("MathF.Sqrt(val1) = "+MathF.Sqrt(val1)); Console.WriteLine("MathF.Sqrt(val2) = "+MathF.Sqrt(val2)); } }
Output
This will produce the following output −
MathF.Sqrt(val1) = 6 MathF.Sqrt(val2) = NaN
Example
Let us now see another example to implement the MathF.Sqrt() method −
using System; public class Demo { public static void Main(){ float val1 = -121f; float val2 = 0f; Console.WriteLine("MathF.Sqrt(val1) = "+MathF.Sqrt(val1)); Console.WriteLine("MathF.Sqrt(val2) = "+MathF.Sqrt(val2)); } }
Output
This will produce the following output −
MathF.Sqrt(val1) = NaN MathF.Sqrt(val2) = 0
Advertisements