Facebook Twitter Gplus LinkedIn YouTube Google Maps RSS
Home Technical List to Observable Collection
formats

List to Observable Collection

Published on July 7, 2010 by in Technical

Consider you are using a LINQ over a ObservableCollection and you want to get the Result Items as a list.

using .ToList(), you will end up in a List and not ObservableCollection

To solve this, you can have a Extension method like this and just use .ToObservableCollection.

public static class ExtensionMethods
{
public static ObservableCollection ToObservableList(this IEnumerable data)
{
ObservableCollection dataToReturn = new ObservableCollection();

foreach (T t in data)
dataToReturn.Add(t);

return dataToReturn;
}
}

A bit Handy. Thats it!!!

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

12,872 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© All rights reserved to Cyberbrutus. 2012
credit

Switch to our mobile site