C# 中的 MathF.Cos() 方法示例

csharpserver side programmingprogramming更新于 2025/8/12 15:37:17

C# 中的 MathF.Cos() 方法返回给定浮点值参数的余弦值。

语法

以下是语法 −

public static float Cos (float val);

以上,Val 是浮点值。

示例

现在让我们看一个实现 MathF.Cos() 方法的示例 −

using System;
class Demo {
   public static void Main(){
      float val1 = 70f;
      float res = (val1 * (MathF.PI)) / 180;
      Console.WriteLine(MathF.Cos(res));
   }
}

输出

这将产生以下输出 −

0.34202

示例

现在让我们看另一个实现 MathF.Cos() 方法的示例 −

using System;
class Demo {
   public static void Main(){
      float val1 = 90f;
      float res = (val1 * (MathF.PI)) / 180;
      Console.WriteLine(MathF.Cos(res));
   }
}

输出

这将产生以下输出 −

-4.371139E-08

相关文章