namespace ConsoleApp1
{
class Program
{
public struct Rect
{
public double width;
public double height;
public Rect(double x,double y) //构造函数,初始化矩形的宽和高
{
width = x;
height = y;
}
public double Area()
{
return width * height;
}
}
static void Main()
{
Rect rect1; //实例化矩形结构
rect1.width = 5;
rect1.height = 3;
Console.WriteLine("矩形面积为:" + rect1.Area());
Rect rect2 = new Rect(6, 4);//使用构造函数实例化矩形结构
Console.WriteLine("矩形的面积为" + rect2.Area());
}
}
}
结构
最新推荐文章于 2019-09-06 15:01:00 发布