如何获取List c#中的数组项
IEnumerable<object> enumerable = c1._getbrandrequest(object[]);
List<object> brand = enumerable.Cast<object>().ToList();
List<Brand> brands = new List<Brand>();
for (int i = 0; i <= enumerable.Count(); i++)
{
var brnd = enumerable.ElementAt(i);
// brnd (intellisense only produce)
// brnd. { Equals, GetHashCode, GetType, ToString }
}
Image of ArrayItems from Web Services
提前致谢!
最佳答案
我认为您的代码可以通过这种方式更简洁一些:
IEnumerable<object> enumerable = c1._getbrandrequest(object[]);
List<Brand> brands = enumerable.OfType<Brand>().ToList();
foreach (Brand brnd in brands)
{
// Do things with brnd.
}
OfType 只返回具有运行时类型 Brand 的对象,结果是一个 IEnumerable,ToList() 将它们放入一个新列表。
关于c# - 如何在 List<object> c# 中获取数组项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611221/