c# - How to find intersection between collections -


suppose have list of containers, each container object. in each container there of objects.

how can find duplicated objects, shared in 2 or more containers?

each container has id,name, list of objects property. each object has id , name.

please see image :

enter image description here

the result should like:

------------- object1.name     object2.name     object3.name ------------- 

i have used incorrect code

  public class container     {         public string id;         public string name;         public string top, left, right, bottom;         public list<objectx> objects = new list<objectx>();      }    public class objectx     {         public string id;         public string name;         public string top, left, right, bottom;      }    list<container> allboundaries = new list<container>();             list<objectx> all_components = new list<objectx>();             container b1 = new container();             b1.name = "boundary1";             b1.id = "1";             allboundaries.add(b1);              container b2 = new container();             b2.name = "boundary2";             b2.id = "2";             allboundaries.add(b2);              container b3 = new container();             b3.name = "boundary3";             b3.id = "3";             allboundaries.add(b3); //----------------------------------------------------------------------------------------             objectx c1 = new objectx();             c1.id = "1";             c1.name = "c1";             b1.objects.add(c1);              objectx c2 = new objectx();             c2.id = "2";             c2.name = "c2";             b1.objects.add(c2);              objectx c3 = new objectx();             c3.id = "3";             c3.name = "c3";             b1.objects.add(c3);              objectx c22 = new objectx();             c22.id = "2";             c2.name = "c2";             b2.objects.add(c2);              foreach (container   bx1 in  allboundaries )             {                  foreach (container bx2 in allboundaries)                 {                     (int = 1; < bx2.objects.count; i++)                          if (bx1.id != bx2.id)                         {                             list<objectx> query = bx1.objects.findall(bx => bx.name == bx2.objects[i].name);                             console.writeline(bx2.objects[i].name + " distributed");                             bx2.objects.remove(bx2.objects[i]);                         }                  }             } 

but gives me objects 1 9, not correct.

assuming have collection of containers, co following:

var item = c in containers            o in c.objects            group c.containername o g            g.distinct().count() > 1            select g.key; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -