using System.Collections;
namespacedemoapp
{
classSample
{
//Array and Araraylist.publicvoidArrayFunction()
{
string[] country = newstring[3];
country[0] = "USA"; //only string value can be added
country[1] = "Denmark";
country[2] = "Russia";
//can store different data types
ArrayList arraylist = new ArrayList();
arraylist.Add(3);
arraylist.Add("USA");
arraylist.Add(false);
}
}
}
Array和 ArrayList 类似。当你想存储相同类型的项目时,可以使用Array。Array具有固定大小。当你要存储任何类型的数据时,我们使用 ArrayList。ArrayList 没有固定大小。参考数组和ArrayList的例子: