Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ C#4.0
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 26-Apr-13 1:07am
Comments
ryanb31 at 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 at 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..
ryanb31 at 26-Apr-13 8:20am
   
And, what does not work mean? Do you get an error? What line?
Dharmendra-18 at 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
ryanb31 at 26-Apr-13 8:27am
   
Does the Remove line even run?
Dharmendra-18 at 27-Apr-13 0:04am
   
control goes on chklist.Remove(t) lines but it not removes items(data).
Dharmendra-18 at 27-Apr-13 0:11am
   
Suppose we have two list like ...
List list1={1,2,3,4,5};
List list2={2,3,5,6,7};
now i want result like..
List list3={1,4};

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Dharmendra-18 at 27-Apr-13 4:14am
   
thanks it works. :)
Steve44 at 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
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 174
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 27 Apr 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