by
Roland Schumacher alias GENiALi
26. Juli 2010 -- 130
words -- 1 mal gelesen
There, a lot was necessary until I had the spin out or got the right Tip .
Request:
I have an ArrayList of objects of type person in it. ArrayList therefore because the collection must be COM visible. Generics do not work there.
I wanted to have the convenience to make type-safe queries, but also on an ArrayList. If you have the hang in LINQ to Objects out times one wants to make it no longer.
ArrayList arl = new ArrayList();
arl.Add(new Person(){ID= .......});
arl.Add(new Person(){ID= .......});
arl.Add(new Person(){ID= .......});
Person person = arl.Where(p => p.ID == ID).FirstOrDefault(); //Geht nicht.
Solution:
Person person = arl.OfType<Person>().Where(p => p.ID == ID).FirstOrDefault();
Just between the collection and where a OfType < T > () reinhängen.
And as I said, I would like to to generics. But COM visible not possible therefore.

cd0a62b9-ea92-4573-8a98-7d86afa94aba|0|.0
Tags: