I have a 2d array returned from a function (c#) and I want to print it (to show the new matrix) here is the code:
using System;
using System.Dynamic;
namespace Quera
{
class Matrix
{
private int r1;
private int c1;
private int[,] mat1;
public int[,] multiply_matrix(int r2, int c2)
{
int[,] mat2 = new int[r2, c2];
int[,] mat3 = new int[r1, c2];
// Enter data mat2
for (int i = 0; i < r2; i++)
{
for (int j = 0; j < c2; j++)
{
mat2[i, j] = Console.Read();
}
}
// Multiply
if (c1 != r2)
{
Console.WriteLine("Matrix multiplication not possible");
}
else
{
for (int i = 0; i < r1; i++)
{
for (int j = 0; j < c2; j++)
{
mat3[i, j] = 0;
for (int k = 0; k < c1; k++)
{
mat3[i, j] += mat1[i, k] * mat2[k, j];
}
}
}
}
return mat3;
}
public Matrix(int r, int c)
{
mat1 = new int[r, c];
r1 = r;
c1 = c;
// Enter data
for (int i = 0; i < r1; i++)
{
for (int j = 0; j < c1; j++)
{
mat1[i, j] = Console.Read();
}
}
}
}
class Program
{
static void Main(string[] args)
{
string[] tokens = Console.ReadLine().Split();
int[] enteries = new int[2];
enteries[0] = Convert.ToInt32(tokens[0]);
enteries[1] = Convert.ToInt32(tokens[1]);
string[] token = Console.ReadLine().Split();
int[] entery = new int[2];
entery[0] = Convert.ToInt32(token[0]); // you have to pass it to multiply_matrix
entery[1] = Convert.ToInt32(token[1]); // you have to pass it to multiply_matrix
Matrix matrix = new Matrix(enteries[0], enteries[1]);
Console.WriteLine(**???**);
}
}
}
what should I write in '???' section (last line of code) to print the whole array (mat3 returned from multiply_matrix function)? I've tried to write Console.WriteLine(matrix.multiply_matrix(entery[0], entery[1])[0]); but it can't be done this way..