因此,事实证明并非创建的所有阵列等.多维数组可以具有非零下限.请参阅Excel PIA的Range.Value属性object[,] rectData = myRange.Value;
我需要将这些数据转换为锯齿状数组.我第一次尝试下面的复杂气味.有什么优化建议吗?它需要处理下限可能不为零的一般情况.
我有这个ex方法:
public static T[][] AsJagged<T>( this T[,] rect )
{
int row1 = rect.GetLowerBound(0);
int rowN = rect.GetUpperBound(0);
int col1 = rect.GetLowerBound(1);
int colN = rect.GetUpperBound(1);
int height = rowN - row1 + 1;
int width = colN - col1 + 1;
T[][] jagged = new T[height][];
int k = 0;
int l;
for ( int i = row1; i < row1 + height; i++ )
{
l = 0;
T[] …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我有很多这样的代码:
int[][] a = new int[firstDimension][];
for (int i=0; i<firstDimension; i++)
{
a[i] = new int[secondDimension];
}
Run Code Online (Sandbox Code Playgroud)
元素的类型是不同的.
有没有办法写一个像这样的方法
createArray(typeof(int), firstDimension, secondDimension);
Run Code Online (Sandbox Code Playgroud)
并得到new int[firstDimension][secondDimension]?
再一次,元素的类型仅在运行时才知道.