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