Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MatrixAddition
- {
- public int[,] Do (int[,] left, int[,] right)
- {
- try
- {
- int[,] res = new int[left.GetLength(0), left.GetLength(1)];
- if (CheckOnCorrect(left, right))
- {
- for (int i = 0; i < left.GetLength(0); i++)
- {
- for (int j = 0; j < right.GetLength(1); j++)
- {
- res[i,j] = left[i, j] - right[i, j];
- }
- }
- }
- else
- throw new Exception("Нам дали массивы разных размерностей в методе Do класса MatrixAddition!");
- return res;
- }
- catch (Exception e)
- {
- Console.WriteLine($"Непредвиденная ошибка в методе Do в классе MatrixAddition. Код ошибки: {e.Message}");
- return left;
- }
- }
- public bool CheckOnCorrect(int[,] left, int[,] right)
- {
- switch(left.Length==right.Length)
- {
- case true:
- {
- return true;
- break;
- }
- case false:
- {
- return false;
- break;
- }
- default:
- {
- Console.WriteLine("Bred v metode CheckOnCorrect v classe MatrixAddition!");
- return false;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement