I am trying to follow the advices of How to resize multidimensional (2D) array in C#?
However, they do not explain how is the syntax to call the solutions they explained there.
Suppose I have the function,
void ResizeArray<T>(ref T[,] original, int newCoNum, int newRoNum)
{
var newArray = new T[newCoNum, newRoNum];
int columnCount = original.GetLength(1);
int columnCount2 = newRoNum;
int columns = original.GetUpperBound(0);
for (int co = 0; co <= columns; co )
Array.Copy(original, co * columnCount, newArray, co * columnCount2, columnCount);
original = newArray;
}
and I want to change the size of a double array [,] myMatrix,
How do I call that function, I have been trying,
ResizeArray(myMatrix, 3,3)
but I keep getting errors and I don't understand.
The error says:
Error CS0411: The type arguments for method 'Program.ResizeArray(ref T[,], int, int)' cannot be inferred from the usage. Try specifying the type arguments explicitly. (CS0411)
If I google this error, I don't get any answer for this particular problem. Therefore, I need to ask you. This is all the information I can provide, there is really nothing else. I have a matrix 2x2 and I need to resize it to nxn with a changing n. The solution I found is the one I pasted and the error I get is also pasted.
Hope somebody can help. Regards
CodePudding user response:
You have to specify what T
is. Assuming myMatrix
contains elements of type double
, you need
ResizeArray<double>(myMatrix, 3, 3)