How do I write an extension method for a generic type with constraints on type parameters?
问题 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. At first I want to show you a dummycode existing class: public class Matrix<T> where T : new() { ... public T values[,]; ... } I want to extend this class in the following way: public static class MatrixExtension { public static T getCalcResult<T>(this Matrix<T> mat) { T result = 0; ... return result