浪花不再归海 2021-10-03 15:26 采纳率: 100%
浏览 126
已结题

如何用c#定义盒子box类?

img

  • 写回答

1条回答 默认 最新

  • CSDN专家-showbo 2021-10-03 15:31
    关注

    题主要的代码如下,有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~

    img

    using System;
    namespace ConsoleApp1
    {
        class Box
        {
            public double Length { get; set; }
            public double Width { get; set; }
            public double Height { get; set; }
            public void SetBox(double Length,double Width, double Height)
            {
                this.Length = Length;
                this.Width = Width;
                this.Height = Height;
            }
            public double GetVolume()
            {
                return Length * Width * Height;
            }
            public double GetArea() {
    
                return (Length * Width + Length * Height + Width * Height) * 2;
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
    
                var box = new Box { Length = 3, Width = 4, Height = 5 };
                Console.WriteLine("体积:" + box.GetVolume());
                Console.WriteLine("面积:" + box.GetArea());
                box.SetBox(5, 5, 5);
                Console.WriteLine("体积:" + box.GetVolume());
                Console.WriteLine("面积:" + box.GetArea());
    
                Console.ReadKey();
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 创建了问题 10月3日

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?