用索引器 来操作动态数组(ArrayList)行不通 为什么?小白求助
为什么不能操作动态数组 求助啊 网上 似乎没有我看的懂得原因
using System;
using System.Collections;
namespace fourthExcerise
{
class Inset
{
private ArrayList array = new ArrayList(size);
static int size = 5;
public Inset()
{
for (int i = 0; i < size;i++)
{
array[i] =0;
}
}
public int this[int index]
{
get
{
int tmp;
if(index>=0&&index<size)
{
tmp = array[index];//cannot implictly convert type object to int an explicit conversion 这个异常
}
else
{
tmp = 0;
}
return tmp;
}
set
{
if(index>=0&&index<size)
{
array[index] = value;
}
}
}
}
}