title: How do I write an extension method for a generic type with constraints on type parameters?
body: <p>I'm working with a task specific .NET plattform, which is precompiled and not OpenSource.
  For some tasks I need to extend this class, but not by inheriting from it. I simply want to add a method.</p>
  
  <p>At first I want to show you a dummycode existing class:</p>
  
  <pre><code>public class Matrix&lt;T&gt; where T : new() {
      ...
      public T values[,];
      ...
  }
  </code></pre>
  
  <p>I want to extend this class in the following way:</p>
  
  <pre><code>public static class MatrixExtension {
      public static T getCalcResult&lt;T&gt;(this Matrix&lt;T&gt; mat) {
          T result = 0;
          ...
          return result;
      }
  }
  </code></pre>
  
  <p>I've got this syntax from many google links so no idea whether it is correct. The compiler tells me no error, but in the end it doesn't work. In the end I want to call this function in the following way:</p>
  
  <pre><code>Matrix&lt;int&gt; m = new Matrix&lt;int&gt;();
  ...
  int aNumber = m.getCalcResult();
  </code></pre>
  
  <p>So anyone got an idea? Thank you for your help!</p>
  
  <p>Regards Nem</p>