A perfect blend of Iterator,Delegate,Predicates,Anonymous method and Generics C#2.0. One can make use of these in real world scenario to save memory and increase performance of an application.
Delegates defines signature of any method that takes one input parameter and returns a single object of another type.
public delegate Tout Action(Tin element); protected void Page_Load(object sender, EventArgs e) { foreach (string str in GetFormatedCustomerName()) Response.Write(str); } public IEnumerable GetFormatedCustomerName() { List customerList=new List(); customerList.Add(new Customer("001", "Santosh",3552)); customerList.Add(new Customer("002", "Poojari", 42424)); customerList.Add(new Customer("005", "Arjun", 42424));
return BuildFormattedName(customerList, delegate(Customer objCustomer) { return string.Format("{0} - {1} ", objCustomer.CustomerId, objCustomer.CustomerName); }); } public IEnumerable BuildFormattedName(IEnumerable list, Action handler) { foreach (Tin entry in list) yield return handler(entry); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|