How to Use LINQ OfType<>
LINQ OfType<> is a useful filtering function for returning items in a collection which match a specific type (or base type). An example might be for getting base items from a listbox of combobox.
An example without OfType:
ColorWrapper x = combo.Items.Where( obj => obj is ColorWrapper ).Cast< ColorWrapper >().FirstOrDefault(cw => cw.Color == value);
An example of LINQ OfType:
ColorWrapper y = combo.Items.OfType<ColorWrapper>().FirstOrDefault(cw => cw.Color == value);
loading...
loading...
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.

Great Post!…
[...] I found your entry interesting thus I’ve added a Trackback to it on my weblog :) [...]…
loading...
loading...