C# .SinCos()
The Math.SinCos() method returns both the sine and cosine of a specified angle (in radians) as a tuple.
Syntax
Math.SinCos(angle);
Parameters:
angle: A double-precision floating-point number representing an angle in radians.
Return value:
The method returns a tuple containing both the sine and cosine of the angle as double values. If the value of angle equals NaN, NegativeInfinity, or PositiveInfinity, the method returns NaN for both values.
Note: This method is more efficient than calling
Math.Sin()andMath.Cos()separately when both values are needed.
Example 1
In this example, the code converts 45 degrees to radians and uses the Math.SinCos() method to return both the sine and cosine of that angle:
using System;public class Example {public static void Main(string[] args) {double degrees = 45;double radians = degrees * Math.PI/180;var (sine, cosine) = Math.SinCos(radians);Console.WriteLine("The sine of " + degrees + " degrees is: " + sine);Console.WriteLine("The cosine of " + degrees + " degrees is: " + cosine);}}
The example will result in the following output:
The sine of 45 degrees is: 0.7071067811865476The cosine of 45 degrees is: 0.7071067811865476
Example 2
In this example, both sine and cosine values of a 30° angle are calculated using Math.SinCos():
using System;public class Example {public static void Main(string[] args) {// Angle in degreesdouble angle = 30;var (sine, cosine) = Math.SinCos(angle * Math.PI/180);Console.WriteLine("The sine of " + angle + " degrees is: " + sine);Console.WriteLine("The cosine of " + angle + " degrees is: " + cosine);}}
The output of this code is:
The sine of 30 degrees is: 0.5The cosine of 30 degrees is: 0.8660254037844386
Note: The
Math.SinCos()method is supported starting from .NET 6 and later. It is not available in earlier .NET versions.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
- Beginner Friendly.15 hours