Link to home
Start Free TrialLog in
Avatar of juststeve
juststeve

asked on

How to convert List to Enumberable

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>'      
Avatar of djon2003
djon2003
Flag of Canada image

The only I know is to iterate through the Enumerable and to add them one by one to the list.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 http://msdn.microsoft.com/en-us/library/d0cyc8ex.aspx

So, you do something like:

RulesException(new List<ErrorInfo>(myEnumerableValue);