我想有一個人輸入的用戶獲取數據,在我的代碼長度和寬度的值,這裏是我走到這一步:從通過命令行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Rectangle
{
double length;
double width;
double a;
static double Main(string[] args)
{
length = Console.Read();
width = Console.Read();
}
public void Acceptdetails()
{
}
public double GetArea()
{
return length * width;
}
public void Display()
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
public void Main()
{
Rectangle r = new Rectangle();
r.Display();
Console.ReadLine();
}
}
}
試圖用兩個Main
方法解決這個問題的方法是錯誤的?這是我從http://www.tutorialspoint.com/csharp/csharp_basic_syntax.htm複製的代碼我試圖對其進行修改,以獲得有關此編程語言的更多經驗。
'Console.Read'返回1 **字符**,不是整數(或雙倍)你期望的價值。閱讀一些關於'Console.ReadLine'的文檔,'double.Parse' – I4V
與你的例子不同,這個類是靜態的,所以要創建長度,寬度等靜態變量。沒有理由有多個名爲main的方法。將main更改爲static int Main(string [] args),並在底部放置一個返回0。 – dcaswell