📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinApp6_7构造函数长方体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double l = double.Parse(txtL.Text);
double w = double.Parse(txtW.Text);
double h = double.Parse(txtH.Text);
Cuboid cuboid = new Cuboid(l, w, h);
lblInfo.Text="对象创建成功!\n"+"长方体的长、宽、高为:\n"
+cuboid.Length+"、"+cuboid.Width+"、"+cuboid.High+"\n"
+"长方体的体积为:"+cuboid.Cubage( );
}
}
class Cuboid
{
private double length;
private double width;
private double high;
public Cuboid(double l, double w, double h) // 声明构造函数
{
length = l; width = w; high = h;
}
public double Length { get { return length; } set { length = value; } }
public double Width { get { return width; } set { width = value; } }
public double High { get { return high; } set { high = value; } }
public double Cubage() { return length * width * high; }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -