title: Checking for null values if element does not exist
body: <p>I am getting values for a number of elements in a <code>.resx</code> file. On some of the the <code>data</code> elements the <code>&lt;comment&gt;</code> child element does not exist so when I run the following I will get a <code>NullReferenceException</code>.</p>
  
  <pre><code>foreach (var node in XDocument.Load(filePath).DescendantNodes())
  {
      var element = node as XElement;
  
      if (element?.Name == "data")
      {
          values.Add(new ResxString
          {
              LineKey = element.Attribute("name").Value,
              LineValue = element.Value.Trim(),
              LineComment = element.Element("comment").Value  //fails here
          });
      }
  }
  </code></pre>
  
  <p>I have tried the following:</p>
  
  <pre><code>LineComment = element.Element("comment").Value != null ? 
                element.Element("comment").Value : ""
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>LineComment = element.Element("comment").Value == null ?
                "" : element.Element("comment").Value
  </code></pre>
  
  <p>However I am still getting an error? Any help appreciated. </p>