Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a ListItemCollection into a 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;

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.

like image 977
Jerameel Resco Avatar asked Jan 24 '11 07:01

Jerameel Resco


1 Answers

var result = rank.Cast<ListItem>().ToArray();
like image 119
Bonshington Avatar answered Sep 19 '22 08:09

Bonshington