我怎么能转换成一个列表<>到一个多维数组? [英] How can I convert a list<> to a multi-dimensional array?

查看:94
本文介绍了我怎么能转换成一个列表<>到一个多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的方法签名:

public void MyFunction(Object[,] obj)

我创建这个对象:

I create this object:

List<List<Object>> obj = new List<List<Object>>;

有一个简单的方法,我可以转换成一个对象[,]


事实上,我喜欢用列表因为我可以很容易地添加新项目。有没有一种方法,我可以宣布我的名单,其中;&GT; 对象,以适应这种需要?我知道,列在我的对象数量[,] 而不是行数。

The fact is I like to use Lists because I can easily add a new item. Is there a way I can declare my List<> object to fit this need? I know the number of columns in my Object[,] but not the number of rows.

推荐答案

没有。其实,这些都是不一定兼容阵列。

No. In fact, these aren't necessarily compatible arrays.

[,] 定义多维数组。 名单,其中,名单&LT; T&GT;&GT; 将对应更多的交错数组(对象[] []

[,] defines a multidimensional array. List<List<T>> would correspond more to a jagged array ( object[][] ).

的问题是,你的原始对象,每个名单,其中,对象&gt; 包含在列表清单中可以有不同数目的对象。您需要为使内部列表最大长度多维数组,并与空值垫或类似的规定,使之匹配。

The problem is that, with your original object, each List<object> contained in the list of lists can have a different number of objects. You would need to make a multidimensional array of the largest length of the internal list, and pad with null values or something along those lines to make it match.

这篇关于我怎么能转换成一个列表&LT;&GT;到一个多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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