Perhaps this method will be useful for someone. You can improve this by adding multiply functions to the fabric-library class.
UPDATE It may be that Operators from the post of JerKimball got into a consultant
class Matrix <T> { T[][] elements; public Matrix(Func<T, T, T> add, Func<T,T,T> multiplicate) { this.Add = add; this.Mult = multiplicate; } public Matrix<T> operator +(Matrix<T> p1, Matrix<T> p2) { // correct this var t = Add(p1.elements[0][0], p2.elements[0][0]); return this; } public Matrix<T> operator *(Matrix<T> p1, Matrix<T> p2) { // correct this var t = Mult(p1.elements[0][0], p2.elements[0][0]); return this; } private Func<T, T, T> Add { get; set; } private Func<T, T, T> Mult { get; set; } } static void Main(string[] args) { var m1 = new Matrix<int>((x,y) => x + y, (x,y) => x * y); var m2 = new Matrix<int>((x, y) => x + y, (x, y) => x * y); }
UPDATE 2
just grant access to the following properties:
public T[][] Elements { get; set; }
and you can do this:
m1.Elements[0][0] = 10; var m3 = new Matrix<int?>((x, y) => x + y, (x, y) => x * y); m3.Elements[0][0] = null;
gabba source share