From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

Learn how to use select to project into another type

Learn how to use select to project into another type - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Learn how to use select to project into another type

- [Instructor] Another scenario that we've talked about is using select to return a sequence of a different type from the original sequence. That's what I'm doing here, remember that get colors returns a list of web color and instead of saying select color, I'm using a property on the web color class. And if you look at this, you'll see that that's an int property, so that means when I run this query, I get back an I numerable of int 32, there's the 140 web colors in there, but I'm only seeing the blue value in this output. Let me come in at this line and try this with a second query let's see what we get when we run this, I get back an I numerable of string. Can you see why that's true? On line 11, I'm selecting out just one property on the web color class called ColorName and that happens to be of type string. This is easy to do, you can choose any of the properties on the underlying type. It's also possible for…

Contents