I made this method in a generic class. I want to sum two matrices if the type is ? Because the compiler says the "'+=' operator cannot be applied to operands type 'T' and 'T'".
Here's the code:
public static Matrix<T> operator +( Matrix<T>m1, Matrix<T>m2)
{
if(m1.Length!=m2.Length)
{
throw new MatrixSizeMisMatchException("different size");
}
if(m1.GetType()!=m2.GetType())
{
throw new MatrixDifferentTypeException("type mismatch");
}
for(int i=0;i<m1.Length;++i)
{
for(int j=0;j<m1.Length;++j)
{
m1[i,j] += m2[i,j];// And here's the problem
}
}
}
The Length attribure is same for all matrices, because I work only 'NxN' matrices.