交错数组< - >多维数组中的ASP.NET转换 [英] jagged arrays <-> multidimensional arrays conversion in ASP.NET

查看:194
本文介绍了交错数组< - >多维数组中的ASP.NET转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一些帮助创建以下convertions:

I would like some help to create the following convertions:

一个需要转换的800 * 600多维数组交错数组,然后以相反的同样的方法(锯齿形阵列使用相同的数据到原来的多维数组)

A need to convert an 800*600 multidimensional array into a jagged array and then the same method in reverse (jagged array with the same data to the original multidimensional array)

这可能吗?任何关于它的帮助?

Is this possible? and any help about it?

推荐答案

我知道这个问题是有点老,但针对的flexability的缘故,我modfied方法的位计算方法中的数组的大小,而不是必须通过他们:

I realize the question is a bit old but for flexability sake, I modfied the method a bit to calculate the array sizes within the method as opposed to having to pass them in:

    static object[][] convertToJaggedArray(object[,] multiArray)
    {
        int firstElement = multiArray.GetLength(0);
        int secondElement = multiArray.GetLength(1);

        object[][] jaggedArray = new object[firstElement][];

        for (int c = 0; c < firstElement; c++)
        {
            jaggedArray[c] = new object[secondElement];
            for (int r = 0; r < secondElement; r++)
            {
                jaggedArray[c][r] = multiArray[c + 1, r + 1];
            }
        }
        return jaggedArray;
    }

这篇关于交错数组&LT; - &GT;多维数组中的ASP.NET转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆