title: XLINQ: string vs Convert.ToString() when extracting element values
body: <p>I am new to LINQ and using it to query XML (it's incredible). I have the following function which simply creates a new <code>List</code> object for each <code>list</code> descendant found in the XML.:</p>
  
  <pre><code>public void ParseLists(XDocument xDoc)
  {
      XNamespace ns = xDoc.Root.Name.Namespace;
      AddRange((
          from e in xDoc.Descendants(ns + "list")
          select new List
          {
              Id = (string)e.Element(ns + "id"),
              ItemsLink = (string)e.Element(ns + "items-link"),
              BatchLink = (string)e.Element(ns + "batch-link"),
              Name = (string)e.Element(ns + "name"),
              IsVendor = (string)e.Element(ns + "is-vendor"),
              Levels = (string)e.Element(ns + "levels")
          }).ToList());
  }
  </code></pre>
  
  <p>And here's a snippet of what the XML might look like:</p>
  
  <pre><code>&lt;lists xmlns="www.namespaceurl.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;list&gt;
      &lt;batch-link&gt;www.batchlinkurl.com&lt;/batch-link&gt;
      &lt;id&gt;12345&lt;/id&gt;
      . . .
    &lt;/list&gt;
  &lt;/lists&gt;
  </code></pre>
  
  <p><strong>The Question</strong>: When building the <code>List</code> objects, I initially used <code>Convert.ToString()</code> rather than <code>(string)</code> to get the elements values as a string. What I found was that:</p>
  
  <p><code>Convert.ToString(e.Element(ns + "id"))</code> will return <code>&lt;id&gt;12345&lt;/id&gt;</code></p>
  
  <p>whereas</p>
  
  <p><code>(string)e.Element(ns + "id")</code> will return <code>12345</code>.</p>
  
  <p><strong>Can someone explain why the return value is different?</strong></p>