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();
}
}
int[] intArray={3,4,5,6,7,8}; //在定义时赋值
int[] intArray2 = new int[5]; //先不赋值,则默认值为0
for(int i=0;i<5;i++)
{
intArray2[i]=i; //在循环里赋值
}
类[] 类组= new 类[10];
for(int i=0;i<类组.Length;i++){
类组[i]=new 类();
}
也可以
类[] 类组= new 类[]{new 类(),new 类()};
public string[] aaa = new string[100];
for(int i=0; i<100;i++)
{
///这里可以赋值
}
可以用集合。。。