BindingList<KeyValuePair<string, string>> properties = new BindingList<KeyValuePair<string, string>>();
Code above stores 开发者_C百科around 10-30 objects as KeyValuePair<string, string>
I need to somehow select an element let's say with key "id"
How do I go about that?
properties.Select(k => k.Key == "id").FirstOrDefault();
BindingList
does not directly implement IEnumerable
so FirstOrDefault()
(LINQ to objects) will not work, even when using System.Linq
. You need to target the underlying collection. The following worked for me:
var myObject = ( (IEnumerable<SomeObjectType>) myBindingSource.List ).FirstOrDefault( d => d.SomeProperty == "some property value" );
精彩评论