初学者的问题
下面是小弟的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 体积
{
class Program
{
static void Main(string[] args)
{
Box b1 = new Box();//创建实例化对象
b1.Length = 5;//并给各个字段赋初值
b1.Width = 4;
b1.Height = 6;
Console.WriteLine(b1.getvlume);//将return的结果传递给b1.getvlume
Console.ReadKey();
}
}
class Box
{
private float height;//定义字段
private float width;
private float length;
public float Height//定义属性
{
set{this.height = value;}
get{return this.height;}
}
public float Length
{
set{this.length = value;}
get{return this.length;}
}
public float Width
{
set{ this.width = value; }
get{ return this.width; }
}
public void ClassBox(float height,float length,float width)//判断数值的大小
{
if (height > 0 && length > 0 && width > 0)
{
this.height = height;
this.length = length;
this.width = width;
}
}
public float getvlume()//最后的方法
{
return height * length * width;
}
}
}
小弟是新手 麻烦各位写的直白点
还有一个 我那个计算下的体积为何return不到main函数里的b1.getvlume