Reputation: 21
Can anyone please explain what does the this code does? Just confused on the this portion of the code (this.matrix = new int[rows, cols];
).
class Matrix
{
private int[,] matrix;
public Matrix(int rows, int cols)
{
this.matrix = new int[rows, cols];
}
}
Upvotes: 0
Views: 127
Reputation: 43320
That code assigns a class variable called matrix
a new 2d array that has x number of rows and x number of columns..
Of course these aren't mapped to rows and columns as you would see in excel but basically just saying the first array has rows
length, and the second column
length such as..
row1: col col col
row2: col col col
is a int[2,3]
as is
col1: row row row
col2: row row row
This is all done in the constructor of an instance of a Matrix
You can find more information here
Upvotes: 6