Mangesh barmate

Mangesh barmate

  • NA
  • 118
  • 136.8k

How to Convert normal foreach loop into Lambda expression ?

Feb 19 2013 7:03 AM
 

public static Collection<SalesPlan> GetCurrentPlan(PurchasePlanRequest purchasePlanRequest)

        {

            SalesCustomerManager salesCustomerManager = new SalesCustomerManager();

            SalesCustomer salesCustomer = new SalesCustomer();

           

            salesCustomer.ReportingCustomerNumber = purchasePlanRequest.ReportingCustomerId;

            Collection<SalesPlan> salesPlanCollection = new Collection<SalesPlan>();           

            salesCustomer = salesCustomerManager.GetCustomerLinesPlansCoverages(salesCustomer);

            Collection<SalesPlan> renewalPlan = new Collection<SalesPlan>();

            Collection<SalesPlan> currentPlan = new Collection<SalesPlan>();           

            foreach (SalesLineOfBusiness lob in salesCustomer.SalesLineOfBusinessCollection)

            {

                if(lob.LineOfBusinessCode == purchasePlanRequest.LOBCode)

                {                   

                    foreach (SalesPlan salepln in lob.SalesPlanCollection)

                    {

                        if (salepln.IsCurrentPlan == true)

                        {

                            currentPlan.Add(salepln);

                        }                       

                    }

                }

            }

            return currentPlan;

        }

 

In the green color code foreach loop, I want to use Lambda expression instead of Foreach loop.

Can anybody suggest me approach of doing so….


Answers (1)