Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

populate ObservableCollection<string> using string array

All,

Need some help here.. I have an array of string and need to bind that to ObservableCollection

Thanks in advance.

like image 660
Amit Avatar asked Feb 26 '13 23:02

Amit


1 Answers

The ObservableCollection<T> class can receive an IEnumerable<T> on the constructor. You can use it like this:

string[] items = ...
ObservableCollection<string> observableItems = new ObservableCollection<string>(items);

Edit: If your array changes in the future, your ObsevableCollection won't. If you want that, please, specify it in your question.

like image 130
Oscar Mederos Avatar answered Oct 29 '22 10:10

Oscar Mederos