static void Main(string[] args)
{
IEnumerable<string> errors = GetErrors();
foreach (string error in errors)
{
Console.WriteLine(error);
}
Console.ReadKey();
}
private static IEnumerable<string> GetErrors()
{
return GetMoreErrors().Concat(GetOtherErrors())
.Concat(GetValidationErrors())
.Concat(AnyMoreErrors())
.Concat(ICantBelieveHowManyErrorsYouHave());
}
private static IEnumerable<string> GetMoreErrors()
{
Console.WriteLine("Within GetMoreErrors");
yield return "GetMoreErrors";
}
private static IEnumerable<string> GetOtherErrors()
{
Console.WriteLine("Within Method GetOtherErrors");
yield return "OtherErrors";
}
private static IEnumerable<string> GetValidationErrors()
{
Console.WriteLine("Within GetValidationErrors");
yield return "GetValidationErrors";
}
private static IEnumerable<string> AnyMoreErrors()
{
Console.WriteLine("Within AnyMoreErrors");
yield return "AnymoreErrors";
}
private static IEnumerable<string> ICantBelieveHowManyErrorsYouHave()
{
Console.WriteLine("Within ICantBelieveHowManyErrorsYouHave");
yield return "ICantBelieveHowManyErrorsYouHave";
}
Output:
Within GetMoreErrors
GetMoreErrors
Within Method GetOtherErrors
OtherErrors
Within GetValidationErrors
GetValidationErrors
Within AnyMoreErrors
AnymoreErrors
Within ICantBelieveHowManyErrorsYouHave
ICantBelieveHowManyErrorsYouHave