C#动态数组ArrayList介绍
ArrayList是一种动态数组,其容量可随着我们的需要自动进行扩充.
ArrayList位于System.Collections命名空间中,所以我们在使用时,需要导入此命名空间.
下面,我们还是在Student类的基础上利用ArrayList操作,从而了解ArrayList的用法
View Code
public class Student
{
public Student(){}
public Student(String name,int age,String hobby)
{
this.Name = name;
this.Age = age;
this.Hobby = hobby;
}
private String name;
public String Name
{
get{return name;}
set{name = value;}
}
private int age;
public int Age
{
get{return age;}
set{age = value;}
}
private String hobby;
public String Hobby
{
get{return hobby;}
set{hobby = value;}
}
public void say()
{
Console.WriteLine("大家好,我是'{0}',今年{1}岁,我喜欢'{2}'",
this.Name,this.Age,this.Hobby);
}
}
编写测试类,了解ArrayList的方法
View Code