title: C# - method that accepts any type of parameter (reusing an existing method)
body: <p>I have a method, <code>serializetoxml</code>, that accepts an object of type <code>obj1</code> as its parameter:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          obj1 myobj = new obj1();
          serializetoxml(myobj);    
      }
  }
  
  public class obj1
  {
      public string a { get; set; }
      public int b { get; set; }
      public bool c { get; set; }
  }
  
  public static void serializetoxml(obj1 myobj)
  {
      XmlSerializer myserializer = new XmlSerializer(typeof(obj1));
      TextWriter mywriter = new StreamWriter("C:\\my.xml");
      myserializer.Serialize(mywriter, myobj);
      mywriter.Close();
  }
  </code></pre>
  
  <p>Now I have a class, <code>obj2</code>, that I want to pass as its parameter</p>
  
  <pre><code>public class obj2
  {
      public int a { get; set; }
      public bool b { get; set; }
      public List&lt;string&gt; c { get; set; }
  }
  </code></pre>
  
  <p>How do I reuse the <code>serializetoxml</code> method to be able to accept another type of parameter, so that I will not write the same method again and change the typeof to <code>obj2</code>?</p>
  
  <pre><code>obj2 myobj = new obj2();
  serializetoxml(myobj);
  </code></pre>