如何在BlindingList C#WinForms中查找对象 [英] how to find objects in blindingList C# WinForms
本文介绍了如何在BlindingList C#WinForms中查找对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有存储在绑定到DataGridView控件的bindingList中的对象的集合,我需要能够基于某些属性来定位对象,即每个对象都有一个propertyID.我需要执行此操作而无需遍历整个集合.
有人可以指出正确的方向吗?
预先感谢,
-DA
I have collection of objects that are stored within a bindingList that''s bound to a DataGridView control and I need to be able to locate objects based on certain properties i.e. each object has a propertyID. I need to do this without iterating through the collection.
Can someone please point me the right direction to accomplish this.
Thanks in advance,
-DA
推荐答案
如果要通过其ID查找对象,例如15 = 5
然后:
If you want to find an object by it''s id, for example 15 = 5
then:
var foundObject = myList.Where(o=>o.propertyID == 5).First()
更好:
假设对象是Person的实例:
And Better:
Imagin the object is an instance of Person:
Person person;
var foundObject = myList.Where(o=>o.propertyID == 5);
if(foundObject.Count()>0)
person = foundObject.First();
这篇关于如何在BlindingList C#WinForms中查找对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文