Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1513
  • Last Modified:

ObservableCollection

Is it possible to convert an array to an ObservableCollection?
0
dchau12
Asked:
dchau12
  • 3
  • 2
1 Solution
 
tcullerCommented:
Easily done. I'll do an example using a collection of Doubles:
System.Collections.ObjectModel.ObservableCollection<System.Double> coll = new System.Collections.ObjectModel.ObservableCollection<System.Double>(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double);

Open in new window

0
 
tcullerCommented:
Sorry, that's really crowded -- here:
System.Collections.ObjectModel.ObservableCollection<System.Double> coll
= new System.Collections.ObjectModel.ObservableCollection<System.Double>
(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double);

Open in new window

0
 
dchau12Author Commented:
this works fine in WPF.  My issue is that silverlight does not have an observable collection that takes parameters.   So, assigning the values in the parameter "(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double)"  is not possible.
0
 
tcullerCommented:
Hrm, I've never used Silverlight before. This question might do better in the Silverlight zone, then. I find it odd that Silverlight doesn't employ constructors, though...
0
 
dchau12Author Commented:
I looked into it further and confirmed that silverlight observable collections do not have constructors.  You have to instantiate your observable collection and then use a loop or aggregates to populate it with your objects.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now