Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 183313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:05:36+00:00 2026-05-11T15:05:36+00:00

I have a method in a Silverlight app that currently returns an IList and

  • 0

I have a method in a Silverlight app that currently returns an IList and I would like to find the cleanest way to turn this into an ObservableCollection so:

public IList<SomeType> GetIlist() {    //Process some stuff and return an IList<SomeType>; }  public void ConsumeIlist() {    //SomeCollection is defined in the class as an ObservableCollection     //Option 1    //Doesn't work - SomeCollection is NULL     SomeCollection = GetIlist() as ObservableCollection     //Option 2    //Works, but feels less clean than a variation of the above    IList<SomeType> myList = GetIlist    foreach (SomeType currentItem in myList)    {       SomeCollection.Add(currentEntry);    } } 

ObservableCollection doesn’t have a constructor that will take an IList or IEnumerable as a parameter, so I can’t simple new one up. Is there an alternative that looks more like option 1 that I’m missing, or am I just being too nit-picky here and option 2 really is a reasonable option.

Also, if option 2 is the only real option, is there a reason to use an IList over an IEnurerable if all I’m ever really going to do with it is iterate over the return value and add it to some other kind of collection?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:05:37+00:00Added an answer on May 11, 2026 at 3:05 pm

    You could write a quick and dirty extension method to make it easy

    public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> enumerable) {   var col = new ObservableCollection<T>();   foreach ( var cur in enumerable ) {     col.Add(cur);   }   return col; } 

    Now you can just write

    return GetIlist().ToObservableCollection(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight 4 MVVM app that uses databinding to boolean properties like
I have this method that logs errors from the Silverlight client: [MethodImpl(MethodImplOptions.NoInlining)] public static
The CollectionViewSource.GetDefaultView() method is not in Silverlight 3. In WPF I have this extension
I have a method on my generated partial class like this: var pChildren =
I have a WP7 app (Silverlight) that has a page with a textbox that
I have a Silverlight Windows Phone 7 app that pulls data from a public
Assume that I have Silverlight app doing a call to a WCF service: void
I have a Silverlight app that consumes a WCF service in my asp.net application.The
I have a Silverlight 3 app that that will let users download PDF files
I have a Silverlight app that needs low-level socket support. It's an Out-of-Browser Trusted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.