C# in Depth

Cover of C# in Depth
Order now (3rd edition)

(You are currently looking at the third edition version of this page. This page is also available for the first and second editions.)

Errata for Chapter 12: LINQ beyond collections

P346, section 12.3.1: XText creation

When describing XText, the book states:

XText is rarely instantiated directly in user code; instead, when a string is used as the content of an element or document, that’s converted into an XText instance.

That's somewhat misleading, as it ignores all the other conversions which implicitly create XText nodes. Basically, any time you create text within an element, it will be a form of XText. For example, consider this code:

new XElement("x", 0)

This creates this XML:

<x>0</x>

The 0 has been specified as an integer literal, but in the object tree there's still an XText object, as you can tell by calling element.Nodes().First().GetType().