How to convert List to Enumberable

Posted on 2011-10-28
Last Modified: 2013-12-16
I'm creating a value from a method that returns an IEnumerable and attempting to send it to a method:

public RulesException(IList<ErrorInfo> errors)

Open in new window

I've tried a few different Cast syntaxes without finding the correct one. I keep hitting:

Error      24      Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<App.Business.ErrorInfo>' to 'System.Collections.Generic.IList<App.Business.ErrorInfo>'      
Question by:juststeve
    LVL 9

    Expert Comment

    The only I know is to iterate through the Enumerable and to add them one by one to the list.
    LVL 62

    Accepted Solution

    Hi juststeve;

    Try it like this, assuming that errors is the IEnumerable

    IList<App.Business.ErrorInfo> = errors .ToList();
    LVL 29

    Expert Comment

    The question sounds like "How to convert List to Enumberable". However you like to do opposite.

    FernandoSoto showed one way. Another is to use a List constructor:

    List<T>(IEnumerable<T>). See

    So, you do something like:

    RulesException(new List<ErrorInfo>(myEnumerableValue);

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now