public Attribute this[int index],this[int 怎么用?

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/09 03:01:24
publicAttributethis[intindex],this[int怎么用?publicAttributethis[intindex],this[int怎么用?publicAttributet

public Attribute this[int index],this[int 怎么用?
public Attribute this[int index],this[int
怎么用?

public Attribute this[int index],this[int 怎么用?
对象自身索引的意思.
public class MyCollection
{
private List m_list;
public MyCollection()
{
m_list = new List();
}
public void Add(Attribute item)
{
m_list.Add(item);
}
public Attribute this[int index]
{
get { return m_list[index]; }
}
static void Main()
{
MyCollection mc = new MyCollection();
mc.Add(new ObsoleteAttribute());
mc.Add(new WebMethodAttribute());
Attribute atti = mc[1]; //WebMethodAttribute
}
}