Skip to content

索引器&集合

L edited this page Apr 21, 2020 · 1 revision

索引器&集合配合使用,实现使用[]获取数据的目的

private List<DataModel> dataList;

public DataModel this[string name]
{
	get { return dataList.Find(x => x.Name == name); }
}

public DataModel this[int index]
{
	get { return dataList[index]; }
}

示例代码

IndexerAndCollection

Clone this wiki locally