public partial class 基础_obj_this : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
book b1=new book("ASP.NET",24.4f);
book b2 = new book("XML", 22f);
book[] arr = new book[] { b1,b2 };
//sinfo s = new sinfo("张三", "男", 20, arr);
sinfo s2 = new sinfo("张三", "男", 20, arr);
Response.Write(s2.info());
}
}
class sinfo
{
private string name;
private string sex;
private uint age;
private book[] b;
public sinfo(string n, string s, uint a, book[] b)
{
this.age = a;
this.sex = s;
this.name = n;
this.b=b;
}
public string info()
{
string all = "";
foreach (book t in b)
{
all += t.bookinfo;
}
return "姓名:" + this.name + "<br>性别:" + this.sex + "<br>年龄:" + this.age + "<br>书籍信息:" + all;
}
}
class book
{
private string bookn;
private float price;
public book(string bn,float p)
{
this.bookn = bn;
this.price = p;
}
public string bookinfo()
{
return this.bookn+","+this.price;
}
}请问下:
1、 foreach (book t in b)
{
all += t.bookinfo;
}
这个t.bookinfo是什么啊,我知道b是传过来的arr数组,t是book类型的,如果直接用 all+=t,结果输出来是 book book
2、这个book是类,怎么实例化后加个[]就成了数组了
{
protected void Page_Load(object sender, EventArgs e)
{
book b1=new book("ASP.NET",24.4f);
book b2 = new book("XML", 22f);
book[] arr = new book[] { b1,b2 };
//sinfo s = new sinfo("张三", "男", 20, arr);
sinfo s2 = new sinfo("张三", "男", 20, arr);
Response.Write(s2.info());
}
}
class sinfo
{
private string name;
private string sex;
private uint age;
private book[] b;
public sinfo(string n, string s, uint a, book[] b)
{
this.age = a;
this.sex = s;
this.name = n;
this.b=b;
}
public string info()
{
string all = "";
foreach (book t in b)
{
all += t.bookinfo;
}
return "姓名:" + this.name + "<br>性别:" + this.sex + "<br>年龄:" + this.age + "<br>书籍信息:" + all;
}
}
class book
{
private string bookn;
private float price;
public book(string bn,float p)
{
this.bookn = bn;
this.price = p;
}
public string bookinfo()
{
return this.bookn+","+this.price;
}
}请问下:
1、 foreach (book t in b)
{
all += t.bookinfo;
}
这个t.bookinfo是什么啊,我知道b是传过来的arr数组,t是book类型的,如果直接用 all+=t,结果输出来是 book book
2、这个book是类,怎么实例化后加个[]就成了数组了
解决方案 »
- 请问如何获取HTTL header的内容就行了
- C# 接收拖放至窗体的文件路径
- 求c#免费打印控件
- vs2003代码同步的问题
- DataRow中的一个问题,,我要获取一个Table中DataRow中某一列的原始值1,而修改后的值不等于1的那些DataRow,,,
- C# STC89C52RC 串口通信,做过的老大来帮帮忙吧。。。
- winFor窗体放大,如何保持图片不变?!
- 请问各位在做邮件的时候,对所接收到的HtmlBody是怎么处理的
- 安装vs.net 2003 后完全不影响老版本的么?
- 如果动态给定2个时间,如如说“2013-10-15”和“2015-03-28”,如何把这时间段每一个日期值,都载入一个string【】数组里?具体代码咋写呢??
- 简单页面问题
- 俺是一个初学者,请教各位大哥大姐一个问题,谢谢帮忙呀
all[1] ==> b[1].bookinfo;all里有两个方法..当all被除法的时候 会全部调用.