我认为这个错误与If语句有关,但是我试过寻找错误,而且大部分问题都是由语法错误引起的,这对我来说似乎不是这样。预先感谢您的帮助。为什么显示无效的表达式项“字符串”?
using System;
namespace FirstConsoleProjectSolution
{
class MainClass
{
public static void Main (string[] args) // this is a method called "Main". It is called when the program starts.
{
string square;
string cylinder;
Console.WriteLine ("Please enter a shape");
if (string == square) {
double length;
double width;
double height;
Console.WriteLine ("Please enter length");
Console.ReadLine (Convert.ToDouble());
Console.WriteLine ("Please enter width");
Console.ReadLine (Convert.ToDouble());
Console.WriteLine ("Please enter height");
Console.ReadLine (Convert.ToDouble());
Console.WriteLine ("Your total volume is" + length * width * height);
}
if (string == cylinder) {
double areaOfBase;
double height;
Console.WriteLine ("Please enter area of base");
Console.ReadLine (Convert.ToDouble());
Console.WriteLine ("Please enter height");
Console.ReadLine (Convert.ToDouble());
Console.WriteLine ("Your total volume is" + areaOfBase * height);
}
}
}
}
谢谢你这么多你得到的错误! – 2015-01-26 21:03:04