var newObj = new Icecream
{
Name = "Rum Raisin Ice Cream",
Ingredients = "Rum, guar gum, nonfat milk, cream, alomnds, sugar,
raisins, honey, chocolate, annatto color...",
Cholestrol = "49mg",
TotalCarbohydrates = "28g",
Protein = new Protein {VitaminA = "2g", Iron = "4g",
Calcium = "1g"},
Price = 10.25,
TotalFat = new TotalFat {SaturatedFat = "5g", TransFat = "3g"}
};
chapter6.Icecream.Add(newObj);
Chapter 6
[ 165 ]
Load Method
This is similar to the Load method that we saw for LINQ to XML, but the difference
is that the Load method here is the typed version of the LINQ to XML's Load method.
Below is a sample which loads the xml file.
var chapter6 = Chapter6.Load("Icecreams.xml");
Here chapter6 is a specific type which is already defined. The un-typed loading in
LINQ to XML can be made typed by casting the un-typed loading with the type that
is required.
In this example, you can see the casting of Chapter6 done to the XElement, used for
loading the XML document into chapterSix, which is a variable equivalent to the
typed XML, chapter6.
Pages:
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254