title: How to find intersection between collections
body: <p>Suppose we have a list of Containers, each container is an object.
  in each container there are some of objects.</p>
  
  <p>How can we find all duplicated objects, which are shared in two or more containers?</p>
  
  <p>Each container has an ID,Name, List of objects  as property.
  Each object has an ID and Name.</p>
  
  <p>Please see the image :</p>
  
  <p><img src="https://i.stack.imgur.com/oSgNN.jpg" alt="enter image description here"></p>
  
  <p>The result should be like:</p>
  
  <pre><code>-------------
  Object1.Name    
  Object2.Name    
  Object3.Name
  -------------
  </code></pre>
  
  <p>I have used some incorrect code</p>
  
  <pre><code>  public class Container
      {
          public string ID;
          public string Name;
          public string Top, Left, Right, Bottom;
          public List&lt;ObjectX&gt; Objects = new List&lt;ObjectX&gt;();
  
      }
  
  
  
  public class ObjectX
      {
          public string ID;
          public string Name;
          public string Top, Left, Right, Bottom;
  
      }
  
  
   List&lt;Container&gt; AllBoundaries = new List&lt;Container&gt;();
              List&lt;ObjectX&gt; all_components = new List&lt;ObjectX&gt;();
              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)
                  {
                      for (int i = 1; i &lt; bx2.Objects.Count; i++)
  
                          if (bx1.ID != bx2.ID)
                          {
                              List&lt;ObjectX&gt; query = bx1.Objects.FindAll(bx =&gt; bx.Name == bx2.Objects[i].Name);
                              Console.WriteLine(bx2.Objects[i].Name + " Distributed");
                              bx2.Objects.Remove(bx2.Objects[i]);
                          }
  
                  }
              }
  </code></pre>
  
  <p>But this gives me all objects from 1 to 9, which is not correct.</p>