如题 假如我创佳一个自定义类型 Student类型 如下
public struct Student
{
public string Name;
public int Age;
}
现在我要创建一个变长的Student类型的数组并给他赋值 如何写? 我写的老提示我没有new 或者没有指明数组大小 可是我要的就是变长的数组啊 ,因为有多少个同学是变化的
2009-05-18 22:45网友采纳
Student[] stus = new Student[5];
赋值方法一:stus[0] = new Student();
赋值方法二:stus = new Student[5]{ new Student(), new Student(), new Student(), new Student(), new Student() }
动态数组可以用泛型:List<Student> stus = new List<Student>();
stus.Add(new Student()); //添加一个Student对象