title: Linq XML query with nested loop - 1
body: <p>In <a href="https://stackoverflow.com/questions/10488217/linq-xml-query-with-nested-loop">this question</a>, if I need to get "date" included in  the output, what changes should be made?</p>
  
  <p>When I included</p>
  
  <pre><code>let dt = l.Element("Date").Value
  </code></pre>
  
  <p>It gives, "Object reference not set to an instance of an object"</p>
  
  <pre><code>var query = from l in doc.Descendants("L1")
              let dt = l.Element("Date").Value
              let id = l.Attribute("id").Value
              from subject in l.Descendants("Subject")
              select new
              {
                  Date = dt,
                  Id = id,
                  SubjectName = (string)subject.Attribute("SubjectName"),
                  Score = (string)subject.Attribute("Score")
              };
  
  
  foreach (var result in query)
  {
      Console.WriteLine(result);
  }
  </code></pre>