Here is the simplified function I want to create:
static List<object> GetAnonList(IEnumerable<string> names) { return names.Select(name => new { FirstName = name }).ToList(); }
In this block of code, I get a compiler error:
Error CS0029 Unable to implicitly convert the type 'System.Collections.Generic.List <>' to 'System.Collections.Generic.List'
The documentation for anonymous types says that anonymous types are treated as a type object. Why doesn't the C # compiler return a List<object> to names.ToList() ?
Also, why is the following code not causing an error? If List<<anonymous type: string FirstName>> cannot be converted to List<object> , then why can it be converted to IEnumberable<object> ?
static IEnumerable<object> GetAnonList(IEnumerable<string> names) { return names.Select(name => new { FirstName = name }).ToList(); }
source share