I have created a separate class library named CommonLogic.cs and using it in Program.cs If I created a object from class Matrices i.e. Matrices mat = new Matrices and try to use it in Program.cs, I am not able to use the object i.e. mat.AdditionOfMatrix_Array()
It gives error. Can anyone guide as to what is wrong.
Program.cs
using CommonLogic;
using System;
namespace UseArrayArrayList_ListForMatrix
class Program
{
public static void Main(string[] args)
{
int m, n, i, j = 0;
char ch;
int[,] Add = new int[10, 10];
Add[i, j] = Matrices.AdditionOfMatrix_Array(i, j, m, n, A, B, Add);
Console.Write("\nSum Matrix :\n");
Matrices.PrintMatrix_Array(i, j, m, n, Add);
break;
CommonLogic.cs
using System;
namespace ArrayArrayList_ListForMatrix
{
public class Matrices
{
public static int AdditionOfMatrix_Array(int i, int j, int m, int n, int[,] X, int[,] Y, int[,] Z)
{
for (i = 0; i < m; i )
{
for (j = 0; j < n; j )
{
Z[i, j] = X[i, j] Y[i, j];
}
}
return Z[i, j];
CodePudding user response:
There is at least one problem in the provided code - Matrices.AdditionOfMatrix_Array
is in ArrayArrayList_ListForMatrix
namespace, you should add appropriate using, i.e. change using CommonLogic;
to using ArrayArrayList_ListForMatrix;
(or just add using ArrayArrayList_ListForMatrix;
if you are using something from CommonLogic
namespace) or change namespace for Matrices
class to CommonLogic
.
See also:
Also I would recommend following C# coding conventions.
CodePudding user response:
There are a couple of problems in your code.
you are not defining or initializing the arrays A
and B
.
and based on your code, I think you want to iterate for i
and j
, something like below.
int m = 3, n = 3;
int[,] A = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int[,] B = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int[,] Add = new int[10, 10];
for (int i = 0; i < m; i )
{
for (int j = 0; j < n; j )
{
Add[i, j] = Matrices.AdditionOfMatrix_Array(i, j, m, n, A, B, Add);
}
}
Also, you have break;
in the Main
method without any loop, which will give a compilation error.
Also, a small suggestion, If you are not using the return value of method AdditionOfMatrix_Array
and only updating it, then you can return void
in place of int
.