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.

Solution: Create custom string output

Solution: Create custom string output - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Solution: Create custom string output

(upbeat electronic music) - I hope you had fun working on this challenge. Here's my results. Remember your solution may be different from mine. You'll find my solution in the CodeChallenges folder. So I start off by loading the XML file. We've seen this in many examples, but here's the code I used to load that example. I stored the root element in this variable called allElements. Then I create my query. I am going to the root element and getting all the elements. Then I'm selecting out the new anonymous type, and I have two properties, ColorName and Formula. The color name is coming from the attribute "color-name." And then the formula is, basically, a interpolated string. So I have the string that I want. Let's see what it looks like when I show the results. I don't like that, I'll run it again. So I have this string and I'm just ticking this value inside the curly braces. This is where the number 139 is coming from,…

Contents