using System;
namespace RectangleApplication
{
class Rectangle
{
double length; //Creating the length and width variables
double width;
public void AcceptDetails() //Getting the details of length and width set in stone
{
length = 4.5;
width = 3.5;
}
public double GetArea() //Multiplying and returning the product of length and width
{
return length * width;
}
public void Display() //Displaying the results
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.AcceptDetails();
r.Display();
Console.ReadKey();
}
}
}
這不是我的程序,我從TutorialsPoint.com獲得它。我理解所有的代碼,直到它到達ExecuteRectangle類,它實例化Rectangle類。需要幫助瞭解C#矩形程序
Rectangle r = new Rectangle();
r.AcceptDetails();
r.Display();
你會用這個做什麼? r.AcceptDetails()
和r.Display()
是做什麼的?
感謝您的閱讀並抱歉,如果帖子馬虎。
這是我的第一個。
不確定你在問什麼。你在Rectangle類中有'AcceptDetails()'和'Display()'方法,所以你可以看到他們在做什麼。一個設置一些變量,另一個顯示它們。 –
閱讀評論,並運行程序請:)評論解釋程序相當好。 – nevets
我在問爲什麼他們在ExecuteRectangle類中。我知道什麼是Display()和AcceptDetails()。 – tristbill