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

Did you find this page helpful?