I hope to get some clarification on the snippet that I recently went through the debugger, but just can't figure it out.
I am taking C # course on PluralSight , and the current section is on yieldand returns IEnumerable<T>with the keyword.
I have this overly basic function that returns a collection IEnumerable Vendors(simple class with Id, CompanyNameand Email):
public IEnumerable<Vendor> RetrieveWithIterator()
{
this.Retrieve();
foreach(var vendor in _vendors)
{
Debug.WriteLine($"Vendor Id: {vendor.VendorId}");
yield return vendor;
}
}
And I have this code in unit test, which I use to test the function:
var vendorIterator = repository.RetrieveWithIterator();
foreach (var item in vendorIterator)
{
Debug.WriteLine(item);
}
var actual = vendorIterator.ToList();
, , , , RetrieveWithIterator , , IEnumerable (. ).