题主要的代码如下,有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~
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();
}
}
}