With the code below i get this error and need help with how to let method Load return List<B>
Cannot implicity convert type System.Collections.Generic.IEnumerable to System.Collections.Generic.List
public class A
{
public List<B> Load(Collection coll)
{
List<B> list = from x in coll select new B {Prop1 = x.title, Prop2 = x.dept};
return list;
}
}
public class B
{
public string Prop1 {get;set;}
public string Prop2 {get;set;}
}
Your query returns an
IEnumerable, while your method must return aList<B>.You can convert the result of your query to a list via the
ToList()extension method.The type of the list should be inferred automatically by the compiler. Were it not, you would need to call
ToList<B>().