using System; using System.Collections; namespace Property { /// <summary> /// PropertyCollection 的摘要说明。 /// </summary> public class PropertyCollection:CollectionWithEvent { public PropertyCollection() { // // TODO: 在此处添加构造函数逻辑 // } public PropertyT this[int index] { get { if( index < this.Count) { return base.List[index] as PropertyT;
} else { return null; }
} }
public PropertyT Add( PropertyT value) { base.List.Add( value as object); return value; } } }
list.Add("aa");
list.Add("bb");
list.Add("cc");
object obja = list[0];
object objc = list[2];//"cc"的索引是2
list.RemoveAt(1);
object objc2 = list[1];//因为移掉第二个元素,所以二个以后的元素的索引都要减一,也就是说,如果要取得"cc"这个元素,索引由原来的2变为1。
我怎么访问不了呢?
ArrayList controlList = new ArrayList();
controlList.Add(textBox1);
controlList.Add(textBox2);
controlList.Add(button1);
if ( (int)button2.Tag == 2 )
controlList.Add(button2);for(int i=0; i < controlList.Count; i++)
{
...
}
using System.Collections;
namespace Property
{
/// <summary>
/// PropertyCollection 的摘要说明。
/// </summary>
public class PropertyCollection:CollectionWithEvent
{
public PropertyCollection()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public PropertyT this[int index]
{
get
{
if( index < this.Count)
{
return base.List[index] as PropertyT;
}
else
{
return null;
}
}
}
public PropertyT Add( PropertyT value)
{
base.List.Add( value as object);
return value;
}
}
}