System.Math un ident

using System; using System.Math; class test { public static void Main() { Console.Write("Enter any value: "); string s=Console.ReadLine(); double n = double.Parse(s); double r = Math.sqrt(n); Console.WriteLine(r); Console.ReadKey(); } } 

I feel that everything is clear in this code, but this code gives compilation errors:
The using using namespace directive can only be applied to namespaces; "System.Math" is a type, not a namespace

How to use math functions? Where do we get a list of all the math functions available in the Math class?

Thanks.

+7
c # mathematical-optimization
source share
4 answers

Math is a static class, not a namespace. It is located in the System namespace.
Therefore, you need to enable the System namespace.
Just use Math.Sqrt and release "using System.Math"; Please note that this is Math.Sqrt, not Math.sqrt

Hope this helps; -)

+24
source share

You have a case sensitivity case

 double r = Math.Sqrt(n); 

http://msdn.microsoft.com/en-us/library/system.math_members(VS.85).aspx

+5
source share

Starting with C # 6.0, you can use

 using static System.Math; 

if you do not want to write Math. all time.

+3
source share

remove using System.Math;

You need to reference the Math class as above. using System; enough

For reference and using the example, see Math class.

+1
source share

All Articles