Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting an ObservableCollection to an array in Silverlight

I'm looking to use the HTML Bridge to send data currently in an ObservableCollection to some JavaScript. I'm assuming that this data would need to be in an array, rather than in an ObservableCollection, for it to be usable in JavaScript. Note: This assumption may be incorrect.

Silverlight doesn't seem to have the ToArray() function on its ObservableCollection class, so I was wondering if there's a nicer way to convert it into an array than iterating over the whole thing.

like image 537
dlanod Avatar asked Feb 26 '23 02:02

dlanod


1 Answers

Silverlight 3 & 4 have the ToArray extension method on any IEnumerable<T>: http://msdn.microsoft.com/en-us/library/bb298736(VS.95).aspx, which an ObservableCollection<T> is.

Make sure you have System.Core referenced and a using System.Linq; at the top of your class.

Note: This should not be taking as confirmation that you have to turn it into an array to send it to Javascript. I don't know about that.

like image 176
Jonathan Rupp Avatar answered Apr 06 '23 19:04

Jonathan Rupp