title: How to convert an XML elements value to an int using linq- c#
body: <p>I'm trying to get the value out of my XML element and convert it to an integer using linq commands so I can do some mathematical equations using it.</p>
  
  <p>This is how I've tried it so far:</p>
  
  <pre><code>private void buttonTab4Mod1Calculate_Click(object sender, EventArgs e)
          {
              var document = XDocument.Load(workingDir + @"\Level4.xml");
  
              var assessmentOneWeight = from d in document.Descendants("moduleTitle")
                                        where d.Value == (String)comboBoxTab4Mod8.SelectedItem
                                        select d.Parent.Element("assessmentOneWeight").Value;
              int a = 0;
              foreach (var item in assessmentOneWeight)
              {
                  a = Convert.ToInt32(item);
              }
              MessageBox.Show(a.ToString());
          }
  </code></pre>
  
  <p>but the value is still 0 for some reason.</p>
  
  <p>This is my xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;SoftwareEngineering&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSE401&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Programming Methodology&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Coursework&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;40&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;40&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Test&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;20&lt;/assessmentThreeWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSC404&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Computer Systems Fundamentals&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Test1&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;30&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Test2&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;30&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Test3&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;40&lt;/assessmentThreeWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;EBSY401&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Information and Data Modelling&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Test&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;25&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework1&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;10&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Coursework2&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;35&lt;/assessmentThreeWeight&gt;
      &lt;assessmentFour&gt;Coursework3&lt;/assessmentFour&gt;
      &lt;assessmentFourWeight&gt;30&lt;/assessmentFourWeight&gt; 
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSC405&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Software Development Principles&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Test1&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;30&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;40&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Test2&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;30&lt;/assessmentThreeWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSC407&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Web Technology&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Tutorials&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;20&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;20&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Exam&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;60&lt;/assessmentThreeWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSC409&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Software Engineering Principles&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Coursework1&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;40&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework2&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;30&lt;/assessmentTwoWeight&gt;
      &lt;assessmentThree&gt;Coursework3&lt;/assessmentThree&gt;
      &lt;assessmentThreeWeight&gt;30&lt;/assessmentThreeWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;ECSC408&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Mathematics for Computing&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Coursework&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;50&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Exam&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;50&lt;/assessmentTwoWeight&gt;
    &lt;/Module&gt;
    &lt;Module&gt;
      &lt;moduleCode&gt;EBSY400&lt;/moduleCode&gt;
      &lt;moduleTitle&gt;Communication and Learning Skills&lt;/moduleTitle&gt;
      &lt;credits&gt;15&lt;/credits&gt;
      &lt;assessmentOne&gt;Coursework&lt;/assessmentOne&gt;
      &lt;assessmentOneWeight&gt;30&lt;/assessmentOneWeight&gt;
      &lt;assessmentTwo&gt;Coursework&lt;/assessmentTwo&gt;
      &lt;assessmentTwoWeight&gt;70&lt;/assessmentTwoWeight&gt;
    &lt;/Module&gt;
  &lt;/SoftwareEngineering&gt;
  </code></pre>
  
  <p>Would greatly appreciate some help.</p>