Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I Have some typical problem issue is

I have two lists and i want to fetch then records which are not common

How can i do this,

Please help me??

shreeniwas kushwah
Posted

Check this link, see if it helps you. It shows how to find common items, so you need to do vice versa of it.
http://stackoverflow.com/questions/11739986/compare-two-lists-to-search-common-items[^]
 
Share this answer
 
Comments
shreeniwas kushwah 30-Jul-13 2:43am    
I want NonCommon Data ......
:)
try this:
XML
int[] a1 = new int[] { 1, 2, 3, 4 };
          int[] b1 = new int[] { 2, 3, 5, 6 };
          List<int> integerList = new List<int>();
          integerList.AddRange(a1.Except(b1));
          integerList.AddRange(b1.Except(a1));
 
Share this answer
 
Comments
Member 9762654 30-Jul-13 3:44am    
this is simpler than mine thanks for teaching me new concept
shreeniwas kushwah 30-Jul-13 4:49am    
:)
praks_1 30-Jul-13 5:02am    
my pleasure
Renju Vinod 30-Jul-13 6:53am    
+5
try this logic

C#
static void Main(string[] args)
        {
           // bool hasDuplicate = false;
            int[] a = new int[] { 1, 2, 3, 4 };
            int[] b = new int[] { 2,3, 5, 6 };
            List<int> integerList = new List<int>();
            List<int> integerListb = new List<int>();
            int cnt = 0;
            int k = 0;
            int k1 = 0;
            for (int i = 0; i < a.Count(); i++)
            {
                cnt = 0;
                for (int j = 0; j < b.Count(); j++)
                {
                    if (a[i] != b[j])
                    {
                        cnt++;
                    }
                    
                }
                if (cnt == b.Count())
                {

                    integerList.Add(a[i]);
                   
                    Console.Write(integerList[k]);
                    
                    k++;
                }
               
            }
            for (int i = 0; i < b.Count(); i++)
            {
                cnt = 0;
                for (int j = 0; j < a.Count(); j++)
                {
                    if (b[i] != a[j])
                    {
                        cnt++;
                    }

                }
                if (cnt == a.Count())
                {

                    integerListb.Add(b[i]);

                    Console.Write(integerListb[k1]);

                    k1++;
                }

            }
                
            Console.Read();
        }
    }


</int></int></int></int>
 
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