title: Linq query to get data from array of objects c#
body: <pre><code>public struct Parameter 
  {
      public Parameter(string name, string type, string parenttype)  
      {        
          this.Name = name;
          this.Type = type;
          this.ParentType = parenttype;        
      }
      public string Name;
      public string Type;
      public string ParentType;
  }
  </code></pre>
  
  <p>Following values are stored in the array of Parameter:</p>
  
  <pre><code>Name        Type                 ParentType
  -------------------------------------------------------
  composite   CompositeType        
  isThisTest  boolean              
  BoolValue   boolean              CompositeType
  StringValue string               CompositeType
  AnotherType AnotherCompositeType CompositeType
  account     string               AnotherCompositeType
  startdate   date                 AnotherCompositeType
  </code></pre>
  
  <p>I want to read this to build an xml. something like:</p>
  
  <pre><code>&lt;composite&gt;
      &lt;BoolValue&gt;boolean&lt;/BoolValue&gt;
      &lt;StringValue&gt;string&lt;/StringValue&gt;
      &lt;AnotherType&gt;
          &lt;account&gt;string&lt;/account&gt;
          &lt;startdate&gt;date&lt;/startdate&gt;
      &lt;/AnotherType&gt;    
  &lt;composite&gt;
  &lt;isThisTest&gt;boolean&lt;/isThisTest&gt;
  </code></pre>
  
  <p>I am using the following logic to read the values:</p>
  
  <pre><code>foreach (Parameter parameter in parameters)
  {
      sb.Append("        &lt;" + parameter.Name + "&gt;");
      //HERE: need to check parenttype and get all it's child elements
      //
      sb.Append("&lt;/" + parameter.Name + "&gt;" + CrLf);
  }
  </code></pre>
  
  <p>Is there a simpler way to read the array to get the parents and thier child? May be using LINQ? I still on .Net 3.5. Appreciate any suggestions with example code :)</p>