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

Ask A Question

Stats

  • Questions 158k
  • Answers 158k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you use svndump and svndumpfilter, you have the choice… May 12, 2026 at 11:18 am
  • Editorial Team
    Editorial Team added an answer No, it's not. You are just declaring a type that's… May 12, 2026 at 11:18 am
  • Editorial Team
    Editorial Team added an answer I believe results, the result of executeFetchRequest:error:, should already be… May 12, 2026 at 11:18 am

Related Questions

I have a Silveright app that allows users to specify filters on a few
How to create a WPF application that can be deployed as either a XBAP
I have a Silverlight 2 application that is consuming a WCF service. As such,
Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.