/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example5_8.cs illustrates the use of out parameters
*/
// declare the MyMath class
class MyMath
{
// the SinAndCos() method returns the sin and cos values for
// a given angle (in radians)
public void SinAndCos(double angle, out double sin, out double cos) {
sin = System.Math.Sin(angle);
cos = System.Math.Cos(angle);
}
}
public class Example5_8
{
public static void Main()
{
// declare and set the angle in radians
double angle = System.Math.PI / 2;
// declare the variables that will be used as out paramters
double sin;
double cos;
// create a MyMath object
MyMath myMath = new MyMath();
// get the sin and cos values from the SinAndCos() method
myMath.SinAndCos(angle, out sin, out cos);
// display sin and cos
System.Console.WriteLine("sin = " + sin + ", cos = " + cos);
}
}
|