I have the following function to get validation errors for a card. My question relates to dealing with GetErrors. Both methods have the same return type IEnumerable&
I don't see anything wrong with your function, I'd say that it is doing what you want.
Think of the Yield as returning an element in the final Enumeration each time that it is invoked, so when you have it in the foreach loop like that, each time it is invoked it returns 1 element. You have the ability to put conditional statements in your foreach to filter the resultset. (simply by not yielding on your exclusion criteria)
If you add subsequent yields later in the method, it will continue to add 1 element to the enumeration, making it possible to do things like...
public IEnumerable ConcatLists(params IEnumerable[] lists)
{
foreach (IEnumerable list in lists)
{
foreach (string s in list)
{
yield return s;
}
}
}