Advertisement
vlad-i-mir-max

Task3

Nov 14th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1.   class MatrixAddition
  2.     {
  3.         public int[,] Do (int[,] left, int[,] right)
  4.         {
  5.             try
  6.             {
  7.                 int[,] res = new int[left.GetLength(0), left.GetLength(1)];
  8.                 if (CheckOnCorrect(left, right))
  9.                 {
  10.                     for (int i = 0; i < left.GetLength(0); i++)
  11.                     {
  12.                         for (int j = 0; j < right.GetLength(1); j++)
  13.                         {
  14.                             res[i,j] = left[i, j] - right[i, j];
  15.                         }
  16.                     }
  17.                 }
  18.                 else
  19.                     throw new Exception("Нам дали массивы разных размерностей в методе Do класса MatrixAddition!");
  20.                 return res;
  21.             }
  22.             catch (Exception e)
  23.             {
  24.                 Console.WriteLine($"Непредвиденная ошибка в методе Do в классе MatrixAddition. Код ошибки: {e.Message}");
  25.                 return left;
  26.             }
  27.         }
  28.         public bool CheckOnCorrect(int[,] left, int[,] right)
  29.         {
  30.             switch(left.Length==right.Length)
  31.             {
  32.                 case true:
  33.                 {
  34.                     return true;
  35.                     break;
  36.                 }
  37.                 case false:
  38.                 {
  39.                     return false;
  40.                     break;
  41.                 }
  42.                 default:
  43.                 {
  44.                     Console.WriteLine("Bred v metode CheckOnCorrect v classe MatrixAddition!");
  45.                     return false;
  46.                     break;
  47.                 }
  48.             }
  49.         }
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement