Skip to content

C# class name problem

Asked Mar 21, 2007, 1:24 PM EDT2 answers
Share
LinkedInX
TypeScript
If I use Math as a class name return should be System.Math.Sqrt(num); in order to program to give output.
If I am not using Math as a class name return can be Math.Sqrt(num); in order to program to give output.

Please explain
using System;
public class Math
{
public static void Main()
{
double sqrt, number;
string sNum;
Console.Write("Number = ");
sNum = Console.ReadLine();
number = Convert.ToDouble(sNum);
sqrt = SqrtRoot(number);
Console.WriteLine("Square Root of the number = {0}", sqrt);
}
public static double SqrtRoot(double num)
{
return System.Math.Sqrt(num);
}
}
/*
Number = 81

Square Root of the number = 9

Press any key to continue

*/

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    You probably don't want to use Math as a class name because it is already being used by .NET as a class.  Consider changing the class to MyMathExample
    0
  • 0
    Thank you for your help Mike
    Maha
    0