如何将ListItemCollection转换为ListItem []? [英] How to convert a ListItemCollection into a ListItem[]?

查看:171
本文介绍了如何将ListItemCollection转换为ListItem []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ListItemCollection转换为ListItem [].

I am trying to convert a ListItemCollection into a ListItem[].

这就是我的代码中的内容.

Here's what I have in my code.

ListItemCollection rank = new
ListItemCollection();

rank.Add(new ListItem("First", "1");
rank.Add(new ListItem("Second", "2");

ListItem[] rankArray = new
ListItem[4];

rankArray = (ListItem[])rank;

C#.NET中的集合是否将其视为数组或其他类型的集合?我对集合和数组有点困惑.希望能找到新的主意,谢谢.

Does a collection in C# .NET treats it as an array or another type of collection? I'm a bit confused on collection and an array. Hoping to find fresh ideas, Thanks in advance.

推荐答案

var result = rank.Cast<ListItem>().ToArray();

这篇关于如何将ListItemCollection转换为ListItem []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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