[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I do this foreach in LINQ>

Posted on 2009-05-01
8
Medium Priority
?
181 Views
Last Modified: 2013-11-11
This cant be that hard but i'm new to LINQ. I want to do this foreach with LINQ.

I think I need to do something like this : orderBasketPayments.ForEach
foreach (var bp in orderBasketPayments)
        {
            if (bp.paymentMethod != "Money Order")
            {
                needCCAuthorization = true;
            }
        }

Open in new window

0
Comment
Question by:Camillia
  • 4
  • 2
  • 2
8 Comments
 
LVL 9

Expert Comment

by:tillgeffken
ID: 24278772
What datatype is orderBasketPayments?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24278985
What about something like:
orderBasketPayments.ForEach(delegate(string input) { if (input != "Money Order") needCCAuthorization = true; });

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 24278995
it's a list. List of class of type BaksetPayment.

Class BaksetPayment has 4 properties.
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 7

Author Comment

by:Camillia
ID: 24279065
Let me try. Just saw your note. Thanks
0
 
LVL 9

Expert Comment

by:tillgeffken
ID: 24279100
Try this

orderBasketPayments.ForEach(delegate(BasketPayment basketPayment)
{
  if (basketPayment.paymentMethod == "Money Order")
    {
       needCCAuthorization = true;
    }
}

Open in new window

0
 
LVL 9

Assisted Solution

by:tillgeffken
tillgeffken earned 800 total points
ID: 24279123
Missing closing brace and semicolon in my previous post.

orderBasketPayments.ForEach(delegate(BasketPayment basketPayment)
{
  if (basketPayment.paymentMethod == "Money Order")
    {
       needCCAuthorization = true;
    }
});

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1200 total points
ID: 24279128
Modified for a BasketPayment :)
orderBasketPayments.ForEach(delegate(BasketPayments input) { if (input.PaymentMethod != "Money Order") needCCAuthorization = true; });

Open in new window

0
 
LVL 9

Expert Comment

by:tillgeffken
ID: 24279160
Made a mistake again there - shoult be != and not == of course. =)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question