title: Adding a class instance as value to a dictionary
body: <p>I've an xml file "Sample.xml"</p>
  
  <pre><code>  &lt;RootElement&gt;
      &lt;Children&gt;
         &lt;Child Name="FirstChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test1" /&gt;
            &lt;Sibling Name="Test2" /&gt;
            &lt;AdditionalSibling Name="Add_Test_1" /&gt;
            &lt;AdditionalSibling Name="Add_Test_2" /&gt;
            &lt;MissingSibling Name="Miss_Test_1" /&gt;
            &lt;MissingSibling Name="Miss_Test_2" /
       &lt;/Child&gt;
  
       &lt;Child Name="SecondChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test3" /&gt;
            &lt;Sibling Name="Test4" /&gt;
       &lt;/Child&gt;
       &lt;Child Name="ThirdChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test5" /&gt;
            &lt;Sibling Name="Test6" /&gt;
        &lt;/Child&gt;
        &lt;Child Name="FourthChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test7" /&gt;
            &lt;Sibling Name="Test8" /&gt;
        &lt;/Child&gt;
        &lt;Child Name="FifthChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test9" /&gt;
            &lt;Sibling Name="Test10" /&gt;
        &lt;/Child&gt;
        &lt;Child Name="SixthChild" Start="0" End="2"&gt;
            &lt;Sibling Name="Test11" /&gt;
            &lt;Sibling Name="Test12" /&gt;
        &lt;/Child&gt;
  
        &lt;MatchedChilds&gt;
           &lt;Child Name="FirstChild" /&gt;
           &lt;Child Name="SecondChild" /&gt;
           &lt;Child Name="ThirdChild" /&gt;
           &lt;Child Name="FourthChild" /&gt;
           &lt;Child Name="FifthChild" /&gt;
           &lt;Child Name="SixthChild" /&gt; 
       &lt;/MatchedChilds&gt;
     &lt;/Children&gt;
   &lt;/RootElement&gt;
  </code></pre>
  
  <p>And a Class "SampleClass"</p>
  
  <pre><code>public class SampleClass
  {
      string Start;
      string End;
      List&lt;string&gt; Siblings;
      List&lt;string&gt; AdditionalSiblings;
      List&lt;string&gt; MissingSiblings;
       public SampleClass()
       {
          Start= "";
          End = "";
          Siblings = new List&lt;string&gt;();
          AdditionalSiblings = new List&lt;string&gt;();
          MissingSiblings = new List&lt;string&gt;();
       }
      public SampleClass( string St, string En,List&lt;string&gt; S, List&lt;string&gt; AS, List&lt;string&gt; MS)
      {
          Start= St;
          End = En;
          Siblings = S;
          AdditionalSiblings = AS;
          MissingSiblings = MS;
      }
  
  }
  </code></pre>
  
  <p>and in another class i've declared a Dictonary Like</p>
  
  <pre><code> Dictionary&lt;string, SampleClass&gt; m_dictSample = new Dictionary&lt;string, SampleClass&gt;();
  </code></pre>
  
  <p>i need to fill this dictonary with the contents of the file ..</p>
  
  <p>I'm using Xml Linq for this..</p>
  
  <pre><code>XDocument l_XDOC = XDocument.Load(Application.StartupPath + "\\Sample.xml");
  
  m_dictSample = (from element in l_XDOC.Descendants("Child")
                          group element by element.Attribute("Name").Value into KeyGroup
                          select KeyGroup )
                          .ToDictionary(grp =&gt; grp.Key,
                                        grp =&gt; new
                                            SampleClass(grp.Attributes("Start").ToList()[0].Value.ToString(),
                                            grp.Attributes("End").ToList()[0].Value.ToString(),
                                            grp.Descendants("Sibling").Attributes("Name").Select(l_Temp =&gt; l_Temp.Value).ToList(),
                                            grp.Descendants("AdditionalSibling").Attributes("Name").Select(l_Temp =&gt; l_Temp.Value).ToList(),
                                            grp.Descendants("MissingSibling").Attributes("Name").Select(l_Temp =&gt; l_Temp.Value).ToList()));
  </code></pre>
  
  <p>This query is working properly for the above described file.</p>
  
  <p>But if the file have more than one Element with same name, or an element with no "start" and "end" attribute make an exception while 
  executing the query.</p>
  
  <p>I've problem with the following lines</p>
  
  <pre><code>     grp.Attributes("Start").ToList()[0].Value.ToString(),
       grp.Attributes("End").ToList()[0].Value.ToString()
  </code></pre>
  
  <p>please give me a better way to do this</p>
  
  <p>And i need to fill a listView with the contents of the Dictonary like</p>
  
  <pre><code>S.no       Child              Siblings                Additional Siblings            Missing Siblings
  
   1         FirstChild         Test1,Test2             Add_Test_1,Add_Test_2           Miss_Test_1,Miss_Test_2
  
   2         SecondChild        Test3,Test4
  
   3         ThirdChild         Test5,Test6
  </code></pre>
  
  <p>now i'm using for loop for this</p>
  
  <p>please give me a better way to do this..</p>