求个泛型类的注释?

来源:百度知道 编辑:UC知道 时间:2024/06/15 10:44:11
public Customer this[int index]//[int index]是什么意思?仅仅解释//此句就可以...............
Code:------------------------------------------------------
using System;
using System.Collections;
using System.Text;
namespace Generics{

public class CustomerList : CollectionBase{
public CustomerList() { }
public Customer this[int index]{
get { return (Customer)List[index]; }
set { List[index] = value; }
}
public int Add(Customer value)
{return List.Add(value);}
}
}

一楼的对了..索引器..在List加一个索引的功能..
比如 List<Customer> ls=new List<Customer>();
ls.Add(customer);
你在访问结果的时候可以用 ls[0]

public Customer this[int index]{
get { return (Customer)List[index]; }
set { List[index] = value; }
} 这段代码的功能就是让你能使用 ls[0]

这个是索引指示器,代表索引的类型为 int ,这样就可以通过 CustomerList[数字] 来获取对象。

这个类中有个List集合作为他的属性,我们要靠索引来在这个集合中索引出一个对象
public Customer this[int index]
this代表本类的一个对象 ,并且这个索引器会返回一个Customer对象
那么我们传进来个INDEX,索引器里面根据INDEX来返回该类属性list里的一个对象了