title: C# object to XML
body: <p>I am creating an application which requires to convert c# object to XML.</p>
  
  <p>I am using XML Serializer class to achieve this. Here is the code snippet:</p>
  
  <pre><code>public  class Anwer
  {
      public int ID { get; set; }
      public string XML { get; set; }
      public Anwer(int ID, string XML)
      {
          this.ID = ID;
          this.XML = XML;
      }
      public Anwer() { }
  }
  </code></pre>
  
  <p>Here is the main function:</p>
  
  <pre><code>   string AnswerXML = @"&lt;Answer&gt;1&lt;Answer&gt;";
     List&lt;Anwer&gt; answerList = new List&lt;Anwer&gt;();
     answerList.Add(new Anwer(1,AnswerXML));
     AnswerXML = @"&lt;Answer&gt;2&lt;Answer&gt;";
     answerList.Add(new Anwer(2, AnswerXML));
     XmlSerializer x = new XmlSerializer(answerList.GetType());
     x.Serialize(Console.Out, answerList);
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="IBM437"?&gt;
  &lt;ArrayOfAnwer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="h
  ttp://www.w3.org/2001/XMLSchema"&gt;
    &lt;Anwer&gt;
      &lt;ID&gt;1&lt;/ID&gt;
      &lt;XML&gt;&amp;lt;Answer&amp;gt;1&amp;lt;Answer&amp;gt;&lt;/XML&gt;
    &lt;/Anwer&gt;
    &lt;Anwer&gt;
      &lt;ID&gt;2&lt;/ID&gt;
      &lt;XML&gt;&amp;lt;Answer&amp;gt;2&amp;lt;Answer&amp;gt;&lt;/XML&gt;
    &lt;/Anwer&gt;
  &lt;/ArrayOfAnwer&gt;
  </code></pre>
  
  <p>In the above code '&lt;' and '>' are getting replaced by '&lt;' and '&amp;gt';
  How to avoid this?
  I know string replace is one of the way, but I don't want to use it.</p>
  
  <p>Thanks in advance.</p>