Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class MatrixOperations<T>
- {
- public MatrixOperations()
- {
- }
- public static T[,] operator +(T[,] mat1, T[,] mat2)
- {
- if (mat1.GetLength(0)!= mat2.GetLength(0) || mat1.GetLength(1) != mat2.GetLength(1))
- {
- throw new ArgumentException("Matrices are not equal");
- }
- T[,] matResult = new T[mat1.GetLength(0), mat1.GetLength(1)];
- for (int i = 0; i < mat1.GetLength(0); i++)
- {
- for (int j = 0; j < mat1.GetLength(1); j++)
- {
- matResult[i,j] = (dynamic)mat1[i,j] + mat2[i,j];
- }
- }
- return matResult;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement