title: Declaring member function in interface
body: <p>Firstly I am pretty new to C#. I would like to have an interface declare a member function like in the following piece of code</p>
  
  <pre class="lang-cs prettyprint-override"><code>interface IMyInterface {
      void MyAction() {
          // do stuff depending on the output of function()
      }
      void Function();
  }
  </code></pre>
  
  <p>here <code>Function</code> is pure virtual and should be implemented by children of <code>IMyInterface</code>. I could use an abstract class instead of an interface but then I could not inherit from other classes... Say for example that <code>MyAction</code> is recursiverly searching a directory for files and applying <code>Function</code> to any file found to make my example clear.</p>
  
  <p>How to change my design in order to overcome the constraint that interfaces cannot implement classes ?</p>
  
  <p>Edit : In C++ what I would do is using templates as such</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;class A&gt;
  static void MyAction(const A&amp; a) {
      // do stuff depending on the output of A::Function()
  };
  
  class MyClass {
      void Function();
  };
  </code></pre>
  
  <p>I was wondering if there were an elegant way to do this using interfaces in C#.</p>