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

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

问题描述

我需要一些帮助来创建以下转换:

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?

推荐答案

我意识到这个问题有点老了,但为了灵活起见,我稍微修改了方法以计算方法内的数组大小,而不是必须通过他们在:

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, r];
            }
        }
        return jaggedArray;
    }

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

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