private string m_str;
public Item(string item)
{
m_str=item;
}
public override string ToString()
{
return m_str;
}
}
class smartarrylist
{
private ArrayList m_array;
public smartarrylist()
{
m_array=new ArrayList();
}
public void additem(object item)
{
//-----注意这里添加一个弱引用---------------------
m_array.Add(new System.WeakReference(item,false));
}
public object this [int index]
{
get
{
if (index < 0 || index >=this.m_array.Count)
return null;
else
return m_array[index];
}
set
{
if (!(index < 0 || index >=this.m_array.Count))
{
//----hoho,加入的都是弱引用
m_array[index]=new System.WeakReference(value,false);
}