索引器&集合配合使用,實現使用[]獲取數據的目的git
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]; } }
示例代碼
IndexerAndCollectiongithub