Advertisement
Guest User

Untitled

a guest
Mar 18th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2.     using System.Collections.Generic;
  3.     public class MatrixOperations<T>
  4.     {
  5.         public MatrixOperations()
  6.         {
  7.  
  8.         }
  9.         public static  T[,]  operator +(T[,] mat1, T[,] mat2)
  10.         {
  11.             if (mat1.GetLength(0)!= mat2.GetLength(0) || mat1.GetLength(1) != mat2.GetLength(1))
  12.             {
  13.                 throw new ArgumentException("Matrices are not equal");
  14.             }
  15.             T[,] matResult = new T[mat1.GetLength(0), mat1.GetLength(1)];
  16.             for (int i = 0; i < mat1.GetLength(0); i++)
  17. {
  18.                 for (int j = 0; j < mat1.GetLength(1); j++)
  19.                 {
  20.                      matResult[i,j] = (dynamic)mat1[i,j] + mat2[i,j];
  21.                 }
  22. }
  23.             return matResult;
  24.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement