title: How to deserialize XML file with Array?
body: <p>may I know how to serialize and deserialize using C# if there have dynamic number behind of the element ? Block1 and Block2 will be dynamic based on the Block Count.</p>
  <pre><code>&lt;DefectList&gt;
      &lt;BlockCount&gt;2&lt;/BlockCount&gt;
      &lt;Block1&gt;
      &lt;/Block1&gt;
      &lt;Block2&gt;
      &lt;/Block2&gt;
  &lt;/DefectList&gt;
  </code></pre>
  <p>Thanks.</p>
  <pre><code>        public static T Deserialize&lt;T&gt;(this T Value, string xmlPath)
      {
          T ret = default(T);
  
          if (!string.IsNullOrEmpty(xmlPath))
          {
              var serializer = new XmlSerializer(typeof(T));
              using (var tw = new FileStream(xmlPath, FileMode.Open))
              {
                  ret = (T)serializer.Deserialize(tw);
                  tw.Close();
              }
          }
          return ret;
      }
  </code></pre>
  <p>I'm trying to use this method to deserialize. and my model as below</p>
  <pre><code>   public class DefectList
  {
      [XmlElement(&quot;DefectList&quot;)]
      public string DefectList{ get; set; }
  
      [XmlElement(&quot;BlockCount&quot;)]
      public int BlockCount { get; set; }
  
      [XmlElement]
      public ObservableCollection&lt;Block&gt; Block { get; set; }
  }
  </code></pre>