c#中如何向动态数组添加结构体作为元素?
在一个博客上(http://)看到可以给动态数组添加对象作为元素,只复制了几句,前面定义过类student:ArrayList students = new ArrayList();
//实例化几个Student类对象
Student rose = new Student("rose",25,"reading");
Student jack = new Student("jack",28,"singing");
Student mimi = new Student("mimi",26,"dancing");
//利用ArrayList类的add()方法添加元素
students.add(rose);
students.add(jack);
students.add(mimi);
现在我用同样思路给动态数组添加结构体变量作为元素,结果出错,如下:
struct student
{string name;
int math;
int english;
string address;
bool IsPartyNumber;
};
student a={"xiaoming",90,80,"xian",false },
b={"liming",85,85,"ankang",true },
c={"juan",78,74,"henan",false },
d={"feng",85,40,"jiangxi",true };
ArrayList students = new ArrayList();
students.Add(a);
students.Add(b);
students.Add(c);
students.Add(d);
最后这四句出错,为什么?c#中如何向动态数组添加结构体作为元素?
[ 本帖最后由 qianwantao 于 2011-10-4 17:36 编辑 ]