using System;
namespace area
{
class Program
{
static void Main(string[] args)
{
double basse;
double height;
Console.WriteLine("Enter your base length: ");
basse = Convert.ToDouble(Console.ReadLine());
Console.WriteLine( "Enter the height: ");
height = Convert.ToDouble(Console.ReadLine());
double area = Program.triangleArea(basse, height);
Console.WriteLine("Your area is {0:f3}", area);
Console.ReadLine();
double pryrmid = Program.pyramidVolume( triangleArea);
Console.WriteLine(" Pyramid Volume is {0:f3}" , pryrmid);
}
public static double triangleArea(double basse, double height)
{
return (0.5 * basse) * height;
}
public static double pyramidVolume (double triangleArea)
{
return (1/3) * triangleArea;
}
}
}
我正在尝试使用我定义的方法计算金字塔的体积。
一直报错
Argument '1': cannot convert from 'method group' to 'double' (CS1503) - \vmware-host\Shared Folders\Documents\SharpDevelop Projects\WS_6_D\WS_6_D\Program.cs:28,57
和
The best overloaded method match for 'area.Program.pyramidVolume(double)' has some invalid arguments (CS1502) - \vmware-host\Shared Folders\Documents\SharpDevelop Projects\WS_6_D\WS_6_D\Program.cs:28,34
我想知道是否有人可以帮助我走上正轨。
最佳答案
问题是 triangleArea
在
double pryrmid = Program.pyramidVolume(triangleArea);
不是变量,因此它指向静态方法。
请尝试 double pryrmid = Program.pyramidVolume( area);
。
关于c# - 计算面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8328892/