C#中如何定义类的数组,以及给他们赋值?

如题,加入循环中,开辟内存怎么办,赋值怎么办

class Student 
    {
        public Student() { }
        public Student(int _stuId, string _stuName) 
        {
            stuId = _stuId;
            stuName = _stuName;
        }
        public int stuId = 0;
        public string stuName = "";
        public void Display() 
        {
            Console.WriteLine(stuId + "," + stuName);
        }
    }
    class Program
    {
        public static void Main(string[] args)
        {
            Student[] stu = new Student[3];
            stu[0] = new Student(1, "风晴雪");
            stu[1] = new Student(2, "百里屠苏");
            Student stu3 = new Student();
            stu3.stuId = 3;
            stu3.stuName = "欧阳少恭";
            stu[2] = stu3;
            for (int i = 0; i < stu.Length; i++)
            {
                stu[i].Display();
            }
            Console.ReadLine();
        } 
    }

追问

请问第三行什么意思?能帮忙解释一下吗?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-14
int[] intArray={3,4,5,6,7,8}; //在定义时赋值
int[] intArray2 = new int[5]; //先不赋值,则默认值为0
for(int i=0;i<5;i++)
{
intArray2[i]=i; //在循环里赋值
}
第2个回答  2017-06-15
类[] 类组= new 类[10];
for(int i=0;i<类组.Length;i++){
类组[i]=new 类();
}
也可以
类[] 类组= new 类[]{new 类(),new 类()};
第3个回答  2014-03-14
public string[] aaa = new string[100];

for(int i=0; i<100;i++)
{
///这里可以赋值
}追问

类对象数组的赋值也是这样吗?

追答

class dev
{
public string stud;
}

public dev[] one = new dev[100]

for(int i=0;i<100;i++)
{
one[i].stud = "值";
}

第4个回答  2014-03-14
可以用集合。。。
相似回答