Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have two Generic Lists of the same type. FirstList Contains all the possible values getting from one table. while the SecondList conatains some selected values of suppliers getting from ItemTable.

Now i want to exract all values from FirstList which do not exist in the Secondlist. Can anyone please help me. I am trying following but getting error,

Thank you kindly.
Posted
Updated 3-Aug-16 20:46pm

 
Share this answer
 
C#
List<string> First = new List<string>();
          First.Add("A");
          First.Add("D");
          First.Add("B");
          First.Add("C");

          List<string> List = new List<string>();

          List.Add("C");
          List.Add("B");


          IEnumerable<string> Third ;
          Third = First.Except(List);
 
Share this answer
 
v2
Create ResultList

Loop through FirstList

In Loop, if FirstListItem not exists in SecondList add to ResultList

Done.
 
Share this answer
 
Hi,

Check this
C#
string[] names1 = System.IO.File.ReadAllLines(@"../../../names1.txt");
        string[] names2 = System.IO.File.ReadAllLines(@"../../../names2.txt");

        // Create the query. Note that method syntax must be used here.
        IEnumerable<string> differenceQuery =
          names1.Except(names2);

        // Execute the query.
        Console.WriteLine("The following lines are in names1.txt but not names2.txt");
        foreach (string s in differenceQuery)
            Console.WriteLine(s);

        // Keep the console window open in debug mode.
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();</string>


Best Luck
 
Share this answer
 
C#
List<object> Items = new List<object>();

foreach(object obj in List1)
{

if(!List2.Contains(obj))
{

Items.Add(obj);

}

}
 
Share this answer
 
v2
watch this following link , this is a complete solution : http://www.codeproject.com/Articles/1116069/Entity-List-T-data-comparer-Inserted-Deleted-Updat
 
Share this answer
 

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



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