Why can't I converter theIEnumable to a list ?

public IEnumerable GetErrors(string propertyName)
{
return _propertyErrors.GetValueOrDefault(propertyName, null);
}

GetErrors(nameof(Name)).ToList();
public IEnumerable GetErrors(string propertyName)
{
return _propertyErrors.GetValueOrDefault(propertyName, null);
}

GetErrors(nameof(Name)).ToList();
6 Replies
Thinker
Thinker2y ago
Do you have using System.Linq;? Oooh you're returning a non-generic IEnumerable. ToList only works on IEnumerable<T>.
TotechsStrypper
ah crap
TotechsStrypper
noooooooooo the interface FORCE me to return IEnumble
TotechsStrypper
how can I get list out of it ?
Thinker
Thinker2y ago
That's dumb Well, you could do .OfType<string>().ToList() if you're sure the objects will always be strings.
TotechsStrypper
got it