1
Answer

How to Convert normal foreach loop into Lambda expression ?

Mangesh barmate

Mangesh barmate

11y
1.9k
1
 

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)