Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
•   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)
                    {
                        //Compare PlanEffectiveDate is equal to CurrentRenewalDate.
                        if (purchasePlanRequest.PlanEffectiveDate == currentRenewalDate)
                        {
                            if (salepln.IsRenewalPlan == true)
                            {
                                currentPlan.Add(salepln);
                            }
                        }
                        else
                        {
                            if (salepln.IsCurrentPlan == true)
                            {
                                currentPlan.Add(salepln);
                            }
                        }
                    }
                }
            }            return currentPlan;
        }
In the bold code foreach loop, I want to use Lambda expression instead of Foreach loop.
Can anybody suggest me approach of doing so….
Posted 20-Feb-13 1:24am
Comments
Member 8090436 at 20-Feb-13 6:39am
   
Thanks,
But what is in DoStuff() method....
How i do?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can run a loop over a collection using LINQ as below -
lob.SalesPlanCollection.ForEach(i => i.DoStuff());
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

My first question would be WHY? would you want to convert it too Lambda? As I personally dont see anything wrong with the code
 
but to answer your question;
 
 lob.SalesPLanCollection.ForEach(i => 
 {
   //Compare PlanEffectiveDate is equal to CurrentRenewalDate.
   if (purchasePlanRequest.PlanEffectiveDate == currentRenewalDate)
   {
     if (salepln.IsRenewalPlan == true)
     {
       currentPlan.Add(salepln);
     }
     else
     {
       if (salepln.IsCurrentPlan == true)
       {
         currentPlan.Add(salepln);
       }
     }
   }  
 
 });
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100