C# Tutorial C# Advanced C# References

C# Math - Sin() Method



The C# Sin() method returns trigonometric sine of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN, negative infinity or positive infinity, the method returns NaN.

In the graph below, Sin(x) vs x is plotted.

Sin Function

Syntax

public static double Sin (double arg);

Parameters

arg Specify the angle in radian.

Return Value

Returns the trigonometric sine of an angle.

Example:

In the example below, Sin() method is used to find out the trigonometric sine of an angle.

using System;

class MyProgram {
  static void Main(string[] args) {
    double pi = Math.PI;
    Console.WriteLine("Math.Sin(pi/6) = "
                      + Math.Sin(pi/6));
    Console.WriteLine("Math.Sin(pi/4) = "
                      + Math.Sin(pi/4));
    Console.WriteLine("Math.Sin(pi/3) = "
                      + Math.Sin(pi/3));
    Console.WriteLine("Math.Sin(Double.NaN) = "
                      + Math.Sin(Double.NaN));
    Console.WriteLine("Math.Sin(Double.NegativeInfinity) = "
                      + Math.Sin(Double.NegativeInfinity));
    Console.WriteLine("Math.Sin(Double.PositiveInfinity) = "
                      + Math.Sin(Double.PositiveInfinity));
  }
}

The output of the above code will be:

Math.Sin(pi/6) = 0.5
Math.Sin(pi/4) = 0.707106781186547
Math.Sin(pi/3) = 0.866025403784439
Math.Sin(Double.NaN) = NaN
Math.Sin(Double.NegativeInfinity) = NaN
Math.Sin(Double.PositiveInfinity) = NaN

❮ C# Math Methods