1 Star 1 Fork 0

ClearStari99/C Sharp 教程

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
047 C Sharp 类class 成员函数和封装.cs 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
using System;
namespace BoxApplication
{
class Box
{
private double length;
private double breadth;
private double height;
public void SetLength(double len)
{
length = len;
}
public void SetBreadth(double bre)
{
breadth = bre;
}
public void SetHeight(double hei)
{
height = hei;
}
public double GetVolume()
{
return length * breadth * height;
}
}
class Boxtester
{
static void Main(string[] args)
{
Box box1 = new Box();
Box box2 = new Box();
double volume;
box1.SetLength(6.0);
box1.SetBreadth(7.0);
box1.SetHeight(5.0);
box2.SetLength(12.0);
box2.SetBreadth(13.0);
box2.SetHeight(10.0);
volume = box1.GetVolume();
Console.WriteLine("box1 的体积:{0}", volume);
volume = box2.GetVolume();
Console.WriteLine("box2 的体积:{0}", volume);
Console.ReadKey();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/ClearStari99/c-sharp-tutorial.git
git@gitee.com:ClearStari99/c-sharp-tutorial.git
ClearStari99
c-sharp-tutorial
C Sharp 教程
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385