C# C级项目-需要帮助计算周长吗
考虑以下项目: 创建一个新的Windows窗体应用程序项目,并将其名称更改为MyRectangle。创建一个名为Rectangle的类。添加一个名为_height的私有整数变量和另一个名为_width的私有整数变量。为这两个变量添加访问器,称它们为Height和Width。让访问者读写_height和_width变量。添加一个名为GetArea()的公共方法,该方法返回矩形的面积,另一个名为getPermiture()的方法返回矩形的周长。使用下面显示的代码定义这些方法C# C级项目-需要帮助计算周长吗,c#,class,C#,Class,考虑以下项目: 创建一个新的Windows窗体应用程序项目,并将其名称更改为MyRectangle。创建一个名为Rectangle的类。添加一个名为_height的私有整数变量和另一个名为_width的私有整数变量。为这两个变量添加访问器,称它们为Height和Width。让访问者读写_height和_width变量。添加一个名为GetArea()的公共方法,该方法返回矩形的面积,另一个名为getPermiture()的方法返回矩形的周长。使用下面显示的代码定义这些方法 public int G
public int GetArea()
{
return (_width * _height);
}
public int GetPerimeter()
{
return ((2 * _width) + (2 * _height));
}
修改public MyRectangle()方法以创建矩形类的实例。使用高度访问器将矩形高度设置为6,使用宽度访问器将矩形宽度设置为8。调用GetArea()和getPermission()方法,并将结果输出到控制台---项目结束说明---- 我创建了class.cs,如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyRectangle
{
internal class Rectangle
{
// ** Properties **
private int _height = 0;
private int _width = 0;
// ** Accessors for Height**
public int Height
{
set
{
_height = value;
}
get
{
return _height;
}
}
// ** Accessors for Width **
public int Width
{
set
{
_width = value;
}
get
{
return _width;
}
}
public int GetArea()
{
return (_width * _height);
}
public int GetPerimeter()
{
return ((2 * _width) + (2 * _height));
}
}
}
我想我得到了正确的类文件,但除此之外,我完全被卡住了。正确地开发了矩形类,仍然可以重用它
MyRectangle.Rectangle _Rectangle = new MyRectangle.Rectangle();
_Rectangle.Height = 6;
_Rectangle.Width = 8;
int _RectangleArea = _Rectangle.GetArea();
int _RectanglePerimeter = _Rectangle.GetPerimeter();
嗨,代码的第二部分是我做的class.cs文件,这是培训的目标。。。我被困在从表单代码调用类。。。顺便说一句,这不是一个正式的“学分制学校工作”,只是我为了学习C#而参加的一次附带培训。。谢谢你的评论谢谢你的帮助。。。“因为像你这样的政治公众人物,世界变得更好了!”