Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert List<T> to ObservableCollection<T> in WP7

I don't know if it's just too late or what, but I don't see how to do this...

What I'm expecting to do, and what the object browser says is there, is this:

var oc = new ObservableCollection<T>( new List<T>() ); 

But ObservableCollection<T> has a single parameterless constructor. The object browser says there is 2 overloads where List and IEnuerable should be able to be passed in.

Is there something wrong with my setup? Are the constructors not on the phone version? (that would be strange)

If this really doesn't exist, what is the standard way of doing this with WP7 now?

like image 449
Josh Close Avatar asked Apr 06 '11 03:04

Josh Close


People also ask

Can we convert list to object?

In short, to convert an ArrayList to Object array you should: Create a new ArrayList. Populate the arrayList with elements, using add(E e ) API method of ArrayList. Use toArray() API method of ArrayList.


1 Answers

ObservableCollection has several constructors which have input parameter of List<T> or IEnumerable<T>:
List<T> list = new List<T>();
ObservableCollection<T> collection = new ObservableCollection<T>(list);

like image 185
eugene.sushilnikov Avatar answered Sep 27 '22 18:09

eugene.sushilnikov