title: Multiple Inheritance in C#
body: <p>Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability.</p>
  <p>For instance I'm able to implement the missing multiple inheritance pattern using interfaces and three classes like that:</p>
  <pre><code>public interface IFirst { void FirstMethod(); }
  public interface ISecond { void SecondMethod(); }
  
  public class First:IFirst 
  { 
      public void FirstMethod() { Console.WriteLine(&quot;First&quot;); } 
  }
  
  public class Second:ISecond 
  { 
      public void SecondMethod() { Console.WriteLine(&quot;Second&quot;); } 
  }
  
  public class FirstAndSecond: IFirst, ISecond
  {
      First first = new First();
      Second second = new Second();
      public void FirstMethod() { first.FirstMethod(); }
      public void SecondMethod() { second.SecondMethod(); }
  }
  </code></pre>
  <p>Every time I add a method to one of the interfaces I need to change the class <em>FirstAndSecond</em> as well.</p>
  <p>Is there a way to inject multiple existing classes into one new class like it is possible in C++?</p>
  <p>Maybe there is a solution using some kind of code generation?</p>
  <p>Or it may look like this (imaginary c# syntax):</p>
  <pre><code>public class FirstAndSecond: IFirst from First, ISecond from Second
  { }
  </code></pre>
  <p>So that there won't be a need to update the class FirstAndSecond when I modify one of the interfaces.</p>
  <hr />
  <h3>EDIT</h3>
  <p>Maybe it would be better to consider a practical example:</p>
  <p>You have an existing class (e.g. a text based TCP client based on ITextTcpClient) which you do already use at different locations inside your project.  Now you feel the need to create a component of your class to be easy accessible for windows forms developers.</p>
  <p>As far as I know you currently have two ways to do this:</p>
  <ol>
  <li><p>Write a new class that is inherited from components and implements the interface of the TextTcpClient class using an instance of the class itself as shown with FirstAndSecond.</p>
  </li>
  <li><p>Write a new class that inherits from TextTcpClient and somehow implements IComponent (haven't actually tried this yet).</p>
  </li>
  </ol>
  <p>In both cases you need to do work per method and not per class. Since you know that we will need all the methods of TextTcpClient and Component it would be the easiest solution to just combine those two into one class.</p>
  <p>To avoid conflicts this may be done by code generation where the result could be altered afterwards but typing this by hand is a pure pain in the ass.</p>