当有这么多相关的问题但我无法找到/理解我正在寻找的答案时,我觉得问这个很糟糕。
// 2. 开发一个程序将货币 X 转换为货币 Y,反之亦然。
using System;
class Problem2
{
static void Main (string[] args)
{
while (true) {
Console.WriteLine ("1. Currency Conversion from CAD to Won");
Console.WriteLine ("2. Currency Conversion from Won to Cad");
Console.Write ("Choose from the Following: (1 or 2)? ");
int option = int.Parse( Console.ReadLine() );
//double x;
if (option == 1) {
Console.WriteLine ("Type in the amount you would like to Convert CAD to Won: ");
//double y =double.Parse( Console.ReadLine());
//Console.WriteLine( cadToWon( y ) );
Console.WriteLine( cadToWon( double.Parse( Console.ReadLine() ) ));
}
if (option == 2) {
Console.WriteLine ("Type in the amount you would like to Convert Won to CAD: ");
Console.WriteLine( wonToCad (double.Parse( Console.ReadLine())));
}
}
}
double cadToWon( double x )
{
return x * 1113.26;
}
double wonToCad( double x)
{
return x / 1113.26;
}
}
这给了我错误消息“非静态字段,方法或属性'问题2需要对象引用......”我知道如果我在方法前面添加静态,我将能够运行程序但是我想知道为什么我需要它(我认为这是因为 Main 是静态的?)为了使用这些方法而不向它们添加静态,我需要更改什么?
谢谢