大家好, 如果我要调整数组的大小(例如):
Hello guys, If I resize an array doing this (e.g.):
String names[] = new String [1]; int numberofnames = 8; Array.Resize(ref names, numberofnames);如何处理一维以上的数组?:
How can I do for an array with more than one dimension?:
//first column for names, second for places String namesplaces[,] = new String[1,2];我想将数组更改为新的维度,例如[10,2]甚至[20,5];我的意思是,任意数量的行和列. 我只想要一个.NET函数,就像上面给出的"Array.Resize"一样.谢谢
I want to change the array to a new dimension such as [10,2] or even [20,5]; I mean, any number of rows and columns. I ONLY want a .NET function just like the ''Array.Resize'' given above... ¿Does it exist? Thanks
推荐答案private void ResizeArray(ref string[,] original, int cols, int rows) { //create a new 2 dimensional array with //the size we want string[,] newArray = new string[rows, cols]; //copy the contents of the old array to the new one Array.Copy(original, newArray, original.Length); //set the original to the new array original = newArray; } // so this resizes the array to 10 columns and 2 rows.. ResizeArray(list,10,2);
抱歉:)我没有读完你的最后一句话,所以你可以使用它来回答它; System.Collections.ArrayList类,它是一个可调整自身大小的一维数组.如果您有一个ArrayList元素都是ArrayLists,它将作为多维使用,因此它将自动调整数组的大小.
hmm sorry :) I didnt read your last sentence so answer to it you may use; System.Collections.ArrayList class, which is a one-dimensional array that resizes itself. If you have an ArrayList whose elements were all ArrayLists, that will work as a multidimensional, so then it will automatically resize the array.
它不存在. 您可以针对固定维数的数组自己实现此类功能,但我没有解释如何做,因为您可能只知道并询问仅有关您所询问的内容.而且,这样的功能会很慢. 您可以对锯齿状数组使用常规的Array.Resize(例如string[][]),但我没有解释如何做,因为您可能只知道并询问仅有关您所询问的内容.出于同样的原因,我没有解释如何使用像System.Collections.Generic.List这样的集合.
更多推荐
调整数组[,]或数组[] []的大小
发布评论