title: How to serialize a collection of class "Type" as <types> rather than <ArrayOfType> in C#.NET Web API
body: <p>I have a .NET Web API project where I have a Data Transfer Object Class which I want to serialize to XML.</p>
  
  <p>The class (simplified) is basically defined as follows:</p>
  
  <pre><code>[XmlType("user")]
  public class PublicVisibleUserDTO
  {   
      public long id { get; set; }
      public string screenname { get; set; }
  }
  </code></pre>
  
  <p>Now, when I call a function that returns only one element, I get good and proper XML as I expect:</p>
  
  <pre><code>&lt;user&gt;
      &lt;id&gt;123&lt;/id&gt;
      &lt;screenname&gt;john&lt;/screenname&gt;
  &lt;/user&gt;
  </code></pre>
  
  <p>However, when I have a function that returns a collection of this Data Transfer Object I get:</p>
  
  <pre><code>&lt;ArrayOfUser&gt;
      &lt;user&gt;
          &lt;id&gt;123&lt;/id&gt;
          &lt;screenname&gt;john&lt;/screenname&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;id&gt;124&lt;/id&gt;
          &lt;screenname&gt;jane&lt;/screenname&gt;
      &lt;/user&gt;
  &lt;/ArrayOfUser&gt;
  </code></pre>
  
  <p>But what I want is:</p>
  
  <pre><code>&lt;users&gt;
      &lt;user&gt;
          &lt;id&gt;123&lt;/id&gt;
          &lt;screenname&gt;john&lt;/screenname&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;id&gt;124&lt;/id&gt;
          &lt;screenname&gt;jane&lt;/screenname&gt;
      &lt;/user&gt;
  &lt;/users&gt;
  </code></pre>
  
  <p>So basically I want the collection to be returned as "types" (users) rather than "ArrayOfType" (ArrayOfUser). How do I do this?</p>
  
  <p>I have tried applying an XmlArray/XmlArrayAttribute function at the top of the class declaration, but that cannot be applied to a class definition.</p>