Solved

remove object from a collection of objects

Posted on 2014-12-16
4
129 Views
Last Modified: 2014-12-16
How can I remove the "individualItem" object from the pendingOrders collection using the code below?

                IEnumerable<PendingOrders> pendingOrders = dbHelper.getPendingOrders(_mode);

                Item individualItem;

                foreach (PendingOrders order in pendingOrders)
                {
                   // foreach (Item individualItem in order.Items)
                    for (int index = 0; index < order.Items.Count; index++ )
                    {
                        individualItem = new Item();
                        individualItem = order.Items[index];

                        _webServiceURL = string.Format(CCG_GETQUANTITY_URL + "{0}/?token={1}", individualItem.CCGSKU, _ccg_token.ToString());
                        List<CCG_OrderData> ccgData = getCCG_ItemData(_webServiceURL);

                        //-- if the number of items on order is less than what they have in stock, proceed
                        if (individualItem.Quantity <= ccgData[0].Balance_On_Hand)
                        {
                            individualItem.InStock = true;
                            //-- TO DO: add in address verification for US orders
                            //var status = verifyOrderAddress(order, "?token=" + _ccg_token.ToString());
                        }
                        else
                        {
                            individualItem.Remove(index);      <-- getting an error here saying no definition for Remove() exists
                        }
                    }


                    {

                    }
                }

Open in new window

0
Comment
Question by:Big Monty
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
Comment Utility
I think you want to do something like this: order.Items.remove(index)
However, removing the object may cause an error in your loop.
You might need to collect all the items that will be removed during the evaluation loop and then remove the items in a separate loop based on the items that were flagged.
0
 
LVL 32

Author Comment

by:Big Monty
Comment Utility
using

order.Items.Remove(index)

I now get a message saying it has an invalid argument.

I actually have

index--;

as the line right after removing it, so I shouldn't lose any of the objects in the collection
0
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 500 total points
Comment Utility
Seems like "remove" usually wants the object while "removeat" has an index for the argument.  Is "RemoveAt" an option for order.Items?
0
 
LVL 32

Author Closing Comment

by:Big Monty
Comment Utility
that was it, thx!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now