初学者的问题

qq476278641 2012-03-19 12:34:38
下面是小弟的代码:
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
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
whycom 2012-03-19
  • 打赏
  • 举报
回复
Console.WriteLine(b1.getvlume())
gunziyang 2012-03-19
  • 打赏
  • 举报
回复
因为b1内本身就含有数据成员的信息,不需要进行参数传递

[Quote=引用 3 楼 qq476278641 的回复:]

引用 1 楼 whycom 的回复:
Console.WriteLine(b1.getvlume())
那个没有形参和实参 怎么也可以直接传递 求高手赐教
[/Quote]
qq476278641 2012-03-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 whycom 的回复:]
Console.WriteLine(b1.getvlume())
[/Quote] 那个没有形参和实参 怎么也可以直接传递 求高手赐教
  • 打赏
  • 举报
回复
楼上正解

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧