新学c#麻烦指点下
有2个类
第一个:
class example
{
private int id;
private string name;
public void goods(int id,string name)
{
this.id=id;
this.name=name;
}
}
如何在第二个类里面用数组的方式添加id 和name
创建数组 example[] a=null ;
后面应该怎么写? c# class
[解决办法]
class example楼主是这个意思么?
{
public int id;
private string name;
public void goods(int id, string name)
{
this.id = id;
this.name = name;
}
}
class test
{
public void msd()
{
example[] a = new example[5];
for (int i = 0; i < 5; i++)
{
a[i] = new example();
a[i].goods(i, i.ToString());
}
foreach (example exaa in a)
{
Console.WriteLine(exaa.id.ToString());
}
}
}