I am new to C#. I am trying to make a matrix calculator but first I need the user to give me the size of and the contents of said matrix. I have 2 classes.
First class is as follows:
class Assignment1
{
static void Main(string[] args)
{
Console.Write("Please enter the number of rows in the matrix: ");
int row = int.Parse(Console.ReadLine());
Console.Write("Please enter the number of columns in the matrix: ");
int columns = int.Parse(Console.ReadLine());
MatrixN matrix =new MatrixN(row, columns);
int i = 0;
for (double x = 0; x < row; x++)
{
for(double y = 0; y < columns; y++)
{
if(i == 0)
{
Console.Write("Enter first value of the matrix: ");
matrix[x, y] = double.Parse(Console.ReadLine());
i++;
}
else if (i == row * columns)
{
Console.Write("Enter last value of the matrix: ");
matrix[x, y] = double.Parse(Console.ReadLine());
i++;
}
Console.Write("Enter nest value of the matrix: ");
matrix[x, y] = double.Parse(Console.ReadLine());
i++;
}
}
}
}
Second class is:
class MatrixN
{
double[,] m;
public MatrixN(int row, int column)
{
m = new double[row, column];
}
I keep getting the error: cannot apply indexing with [] to an expression of MatrixN for the code
matrix[x, y] = double.Parse(Console.ReadLine());
Any help would be greatly appreciated. Thank you.