通用转换为IEnumerable的数组列表 [英] Convert generic ienumerable to arraylist
本文介绍了通用转换为IEnumerable的数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从通用的IEnumerable到ArrayList中的LINQ查询转换
ArrayList的myArrayList =新的ArrayList();
变种B =
(从MyObj中MyCollection中
选择新MyClass的
{
名称= myObj.Name,
AC = myObj.ac
});
我曾尝试做
b.Cast< ArrayList的>();
,但它不工作。
编辑:
我得到了它与@devdigital解决方案的工作
但我也想指出的是,在同一时间,我发现。一个hackish的解决方案
myArrayList.InsertRange(0,b.ToArray());
解决方案
一个构造函数为的ArrayList
类型需要一个的ICollection
,所以你应该能够做到以下几点:
变种b =
(从MyObj中MyCollection中
选择新MyClass的
{
名称= myObj.Name,
AC = myObj.ac
})ToArray的();
ArrayList的myArrayList =新的ArrayList(B);
I need to convert the linq query from generic ienumerable to arraylist.
ArrayList myArrayList = new ArrayList();
var b =
(from myObj in myCollection
select new myClass
{
Name = myObj.Name,
ac = myObj.ac
});
I have tried doing
b.Cast<ArrayList>();
but it is not working.
Edited : I got it working with @devdigital solution
but i will also want to point out that at same time i found a hackish solution.
myArrayList.InsertRange(0, b.ToArray());
解决方案
One of the constructors for the ArrayList
type takes an ICollection
, so you should be able to do the following:
var b =
(from myObj in myCollection
select new myClass
{
Name = myObj.Name,
ac = myObj.ac
}).ToArray();
ArrayList myArrayList = new ArrayList(b);
这篇关于通用转换为IEnumerable的数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文