Solved

remove object from a collection of objects

Posted on 2014-12-16
4
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 40503302
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 33

Author Comment

by:Big Monty
ID: 40503312
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
ID: 40503337
Seems like "remove" usually wants the object while "removeat" has an index for the argument.  Is "RemoveAt" an option for order.Items?
0
 
LVL 33

Author Closing Comment

by:Big Monty
ID: 40503443
that was it, thx!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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