找对象的索引泛型列表 [英] Get index of an object in a Generic list

查看:97
本文介绍了找对象的索引泛型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义对象具有两个属性作为标识符(IDA,IDB)
每次我删除一个对象,我需要知道它的索引列表。 ?
我如何得到一个对象的指标不用循环所有列表



 列表< CustomObject>名单=新名单,LT; CustomObject>(); 
list.RemoveAll((MiniMapRecord P)=> p.IDa == IDa.SystemID&放大器; p.IDb == pInputRecordMap.IDb);


解决方案

你想用的方法 FindIndex(谓词)

  INT指数= list.FindIndex(MiniMapRecord p => p.IDa == IDa.SystemID&放; p.IDb == pInputRecordMap.IDb); 


I have a list of custom objects with two properties as identifiers (IDa, IDb) everytime i remove an object i need to know it's index. how do i get an index of an object without looping all the list?

List<CustomObject> list =new List<CustomObject>();
list.RemoveAll((MiniMapRecord p) => p.IDa == IDa.SystemID & p.IDb == pInputRecordMap.IDb);

解决方案

The method you want is FindIndex(Predicate)

int index = list.FindIndex(MiniMapRecord p => p.IDa == IDa.SystemID & p.IDb == pInputRecordMap.IDb);

这篇关于找对象的索引泛型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆