SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 40 | Next

Scott Klein

"Professional LINQ"


The following example uses the XElement to construct a simple XML document. The first XElement
defines the outer node while the two inner XElement parameters define the two inner nodes of FirstName
and LastName.
var x = new XElement("Employee",
new XElement("FirstName", "Scott"),
new XElement("LastName","Klein"));
var s - x.ToString();
12
Chapter 1: Project LINQ
Here are the results of this code:

Scott
Klein

You??™ll notice the use of var in the previous example. The var keyword tells the compiler to infer the type
of the variable from the expression on the right side of the statement. The var keyword will be discussed
in detail in Chapter 2, ??????A Look at Visual Studio 2008??™??™.
Also notice in the previous example how much easier the code is to read. The code actually follows the
structure of an XML document, so you can see what the resulting XML document will look like.
The next example uses the XAttribute type to add an attribute to the XML:
var x = new XElement("Employee",
new XAttribute("EmployeeID", "15"),
new XElement("FirstName", "Scott"),
new XElement("LastName","Klein"));
var s - x.


Pages:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6