Wednesday, July 9, 2014

C# Code Tips: Custom Iterator- Yield and Ienumerable

// A generic method to transform one sequence into another:
delegate Tout Action(Tin element);



IEnumerable Transform(IEnumerable list, Action method)

{
foreach (Tin entry in list)

yield return method(entry);



}


public IEnumerable<string> GetCustomerDetails()



{

var customerList =GetCustomerList();
return Transformstring>(customerList,

delegate(Customer item)



{
return CreateCustomerReport(item.CustomerID, item.CustomerName, item.CustomerAddress);



});

}
Post a Comment