From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The OfType method

The OfType method

- Over in LINQPad at the top of my editor, I am calling Getcards and then outputting the entire sequence. So when I run this, we see what's re being returned from my types. I get back and innumerable of card. There are six total items and you can see there's some information here and the price, the description is so on. But what we're interested in this demo is over here in this column the type name. I can see that there are six cards, four of them are Monster cards. One is a Cyborg and one is Android. So now let's see how to use of type. Here On line six, I'm taking my original query and I'm saying I'm interested in OfTypes Monster. Now I want to uncomment this line and run it. I'm going to select only the Monster card type. And then I'm up putting it in this a new anonymous type with the nameless price and type name that looks good. I'm getting back four items that make sense. If I switched this over and use…

Contents