From the course: .NET Essentials: LINQ for XML

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Select data into a new anonymous type

Select data into a new anonymous type - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Select data into a new anonymous type

- [Instructor] One of my favorite features in link to objects is the ability to take the result and project them into a type. It can be predefined type or often we use a on the fly type created in our query. That's called an anonymous type and that's what we're doing here. So we started off the same. I do my query expression and I'm going to query the elements. We'll skip over lines 11 and 12 for a minute. And then down here I select out the new type and I provide the three property values or the property names I should say for that type card name, bid price, and catalog price. And I can see the types over there. It's a string, string and string. And then from my query, I get information. So here I'm pulling information from the attributes. So I'm going to the card name attribute and I'm getting it's value that gets assigned to the card name. And then here, I'm using these variables that it declared within the body…

Contents