Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on System.Math 1

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
US
Hello Everyone

Could someone tell me how to use Trig. Functions in C#
the only thing I can find is using System.Math but I can't
figure out where it put it or how to use it. The only thing
I could find was that in the framework.net docs it says to
put "Imports System.Math" at the beginning of the program
but I must be doing something wrong because I cannot get it
to work. Thanks for any help.

Randy
 
Math is a class, not a namespace (it's actually part of the System namespace), so more than likely you don't have to reference/use any additional namespaces.

If you look at the member info for the Math class (ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemmathmemberstopic.htm) you'll see a yellow "S" beside all the public methods. That means that you don't have instantiate (create an instance of) class Math in order to use them. They're "Static".

So the Pythagorean theorem would be:
Code:
double SideALength, SideBLength;
double HypotenuseLength;
SideALength = 3.0;
SideBLength = 4.0;
HypotenuseLength = Math.Sqrt((SideALength * SideALength) + (SideBLength * SideBLength));
If (double.IsNaN(HypotenuseLength) {
   // Something bad happened
}
Note that I'm using the static method "IsNaN" off the double class to determine if something went wrong in the square root method (you should always check return values).

Hope this helps.

Chip H.
 
That did the trick.
Thank you very much for your help

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top