通过索引器取出ArrayList中的数据。需要注意的是:通过索引器获取的数据类型是object,需通过强制转换得到相应的类型。
例如
// 创建ArrayList
ArrayList al = new ArrayList();
// 添加数据
al.Add(1); //整数
al.Add(3.14f); //单精度浮点
al.Add("Hello"); //
字符串// 使用索引器从ArrayList读取数据,然后进行强制转换
int x = (int)al[0];
int f = (float)al[1];
string s = (string)al[3];