title: C# create DLL Plugin that implements interface
body: <p>I'm writing a simple plugin based program. I have an interface <code>IPlugin</code> which has some methods and functions, and a <code>List&lt;Plugin&gt;</code> in my main program. For the sake of simplicity, lets say its defined like this:</p>
  
  <pre><code>public interface IPlugin
  {
      public void OnKeyPressed(char key);
  }
  </code></pre>
  
  <p>Everytime a key is pressed, I loop through the Plugin list, and call <code>OnKeyPressed(c)</code> on each of them.</p>
  
  <p>I can create a class like so, and add it to the list...</p>
  
  <pre><code>public class PrintPlugin
  {
      public void OnKeyPressed(char key)
      {
          Console.WriteLine(c);
      }
  }
  </code></pre>
  
  <p>And then whenever you press a key, its printed out. But I want to be able to load plugins from DLL files. <a href="https://stackoverflow.com/questions/1087794/c-load-a-dll-file-and-access-methods-from-class-within">This link</a> was helpful, but it doesn't explain how to have the classes in the DLL implement my <code>IPlugin</code> interface... How can I do that? I really don't want to have to copy the <code>IPlugin.cs</code> file every time I want to make a plugin...</p>