The ICollection interface provides a "CopyTo" method that copies the
collection data into an array. However, you can be pretty sure it does this
with a loop.
There is no generic to "convert" a collection to an array that does not
involve copying the elements of the collection: The collection could contain
anything, from a linked list to a database recordset; The only way to
convert these to an array is to copy them element by element, as the memory
layout of an array is completely different from say, a linked list.
Niki
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in
news:%2****************@TK2MSFTNGP12.phx.gbl...
How can I convert (elegant way) Collection to Array without looping and
new instances.
E.G:
I want to add elements of one menu to other, so
secondMenu.MenuItems.AddRange(firstMenu.MenuItems) ; //Error here: Argument
'1': cannot convert from 'System.Windows.Forms.Menu.MenuItemCollection' to
'System.Windows.Forms.MenuItem[]'
So please advice.