Click here to Skip to main content
14,739,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code
List<PurchaseMain> addList = new List<PurchaseMain>();
           List<PurchaseMain> poRecive = new List<PurchaseMain>();
           List<PurchaseMain> poNewGenerate = new List<PurchaseMain>();
           using (InventoryEntities inventoryEntities = new InventoryEntities())
           {
               var poResult = (from res in inventoryEntities.PORecived_Main
                               select new PurchaseMain { RecNo = res.RefNo }).ToList<PurchaseMain>(); ;
               poRecive = poResult;
               var poNewResult = (from res in inventoryEntities.PONewGenerate_Main
                                  select new PurchaseMain { RecNo = res.RefNo }).ToList<PurchaseMain>();
               poNewGenerate = poNewResult;
               foreach (var t in poNewGenerate)
               {
                   poRecive.Add(t);
               }
               var purchaseResult = (from res in inventoryEntities.Purchase_Main
                                     select new PurchaseMain { RecNo = res.RecivedPO }).ToList<PurchaseMain>(); ;
               var chklist = poRecive;
               foreach (var t in purchaseResult)
               {
                   for (int counter = 0; counter < poRecive.Count; counter++)
                   {
                       if (t.RecNo == poRecive[counter].RecNo)
                       {
                           chklist.Remove(t);
                       }
                   }
                   //foreach (var rt in poRecive)
                   //{

                   //}
               }
               addList = chklist;
           }
           return addList;


when it return, it contain same value..
Posted
Comments
ZurdoDev 26-Apr-13 7:38am
   
Return from where? Who calls it? What is this? Put a breakpoint and walk through it and see what is happening and then give us something specific to work with.
Dharmendra-18 26-Apr-13 8:17am
   
this is method which calculate billing id, who is already seen is not for adding.
here remove method not works..
ZurdoDev 26-Apr-13 8:20am
   
And, what does not work mean? Do you get an error? What line?
Dharmendra-18 26-Apr-13 8:25am
   
not giving error. only
foreach (var t in purchaseResult)
{
for (int counter = 0; counter < poRecive.Count; counter++)
{
if (t.RecNo == poRecive[counter].RecNo)
{
chklist.Remove(t);
}
}
//foreach (var rt in poRecive)
//{

//}
}
addList = chklist;
not removes same id data
ZurdoDev 26-Apr-13 8:27am
   
Does the Remove line even run?
Dharmendra-18 27-Apr-13 0:04am
   
control goes on chklist.Remove(t) lines but it not removes items(data).
Dharmendra-18 27-Apr-13 0:11am
   
Suppose we have two list like ...
List<int> list1={1,2,3,4,5};
List<int> list2={2,3,5,6,7};
now i want result like..
List<int> list3={1,4};

1 solution

Your code line
chklist.Remove(t);

is incorrect as it tries to remove the item t (which is an item in the purchaseResult list) from the chklist. As it is not part of the chklist it is not found and so nothing is removed.
To make your code work you need to remove the item that is in the chklist, which is just an alias for the poRevice list.

The code could look like this:
chklist.Remove(poRecive[counter]);
break; // this is assuming RecNo is unique.
   
Comments
Dharmendra-18 27-Apr-13 4:14am
   
thanks it works. :)
Steve44 27-Apr-13 10:42am
   
Glad to help :-)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900