Feed
Google+
Contact
XING
LinkedIn
Twitter
ICQ
meebo.com

C - typed LINQ to objects query on an ArrayList

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.

kick it on dotnet-kicks.de

Tags:

Kommentare sind geschlossen

Statistik

Gesamte Posts: 1025
Dieses Jahr: 7
Diesen Monat: 1
Diese Woche: 0
Kommentare: 929
Total Bewertungen: 91
Ø Bewertung: 4,42
Meisten Kommentare
Google+ ... (28)
Beste Ø Bewertung
Tastaturlayout von Visual Stud ... (5)
Meiste Bewertungen
Windows 7 und die ersten Erfah ... (5)

Buttons

Stop Spam Harvesters, Join Project Honey Pot Benutzerprofil von GENiALi connection speed test network connection Bloggeramt.de Slug.ch Blog Verzeichnis und Blog Webkatalog Schumacher Roland Seitwert Valid XHTML 1.0 Transitional

writing