C#如何利用while循环输出对象数组的全部信息?具体信息如下。 20
XueSheng[]a=newXueSheng[5];a[0]=newXueSheng(5,"张三",15,"沈阳","1米8",100);Console.WriteLi...
XueSheng[] a = new XueSheng[5];
a[0] = new XueSheng(5, "张三", 15, "沈阳", "1米8", 100);
Console.WriteLine(a[0].xianshi());
a[1] = new XueSheng();
a[1].Id = 5;
a[1].Name = "张三";
a[1].Nl = 15;
a[1].Dz = "沈阳";
a[1].Sg = "1米8";
a[1].Cj = 100;
Console.WriteLine(a[1].xianshi());
a[2] = new XueSheng(1, "孙强", 16, "大连", "1米7", 99);
Console.WriteLine(a[2].xianshi());
a[3] = new XueSheng(2, "小红", 18, "深圳", "1米8", 96);
Console.WriteLine(a[3].xianshi()); 展开
a[0] = new XueSheng(5, "张三", 15, "沈阳", "1米8", 100);
Console.WriteLine(a[0].xianshi());
a[1] = new XueSheng();
a[1].Id = 5;
a[1].Name = "张三";
a[1].Nl = 15;
a[1].Dz = "沈阳";
a[1].Sg = "1米8";
a[1].Cj = 100;
Console.WriteLine(a[1].xianshi());
a[2] = new XueSheng(1, "孙强", 16, "大连", "1米7", 99);
Console.WriteLine(a[2].xianshi());
a[3] = new XueSheng(2, "小红", 18, "深圳", "1米8", 96);
Console.WriteLine(a[3].xianshi()); 展开
3个回答
展开全部
int count =0;
while(count<XueSheng.Length)
{
if(a[count]!=null)
{
Console.Write(a[count].Id.ToString());
Console.Write(a[count].Name);
Console.Write(a[count].Nl);
Console.Write(a[count].Dz);
Console.Write(a[count].Sg.ToString());
Console.Write(a[count].Cj);
Console.WriteLine();
}
count++;
}
展开全部
foreach(XueSheng x in a) Console.WriteLine(x.xianshi());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int i=0;
while(i<a.length){
var cur=a[i];
//输出cur信息.
i++;
}
while(i<a.length){
var cur=a[i];
//输出cur信息.
i++;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询