• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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>'      
0
juststeve
Asked:
juststeve
1 Solution
 
djon2003Commented:
The only I know is to iterate through the Enumerable and to add them one by one to the list.
0
 
Fernando SotoCommented:
Hi juststeve;

Try it like this, assuming that errors is the IEnumerable

IList<App.Business.ErrorInfo> = errors .ToList();
0
 
anarki_jimbelCommented:
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);
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now