title: How do I find the intersection of 2 sets in my logfile (using LINQ)
body: <p>At my workplace I have a simplified log file of who has IM'ed (instant messaged) who.  For our simple example, let's pretend the log is a text file that consists of 2 tab-delimited columns.  If person A IM'ed person B, or vice versa, it shows up in the log as AB or BA.  The direction of the IM doesn't matter, just that the pair has been in contact with each other.</p>
  
  <p>I have a list of 2 research groups, X and Y, which contains the names of people like A, B, C, etc.  My goal is to find out who in groups X and Y have IM'ed each other by looking at the log file.  I can't make any assumptions about the members of groups X and Y in terms of quantity of people or distinct members.</p>
  
  <p>If this were a database I'd imagine using joins, but I'd like to learn how to do this with C#/LINQ.  How do I find the intersection of Group X and Group Y inside of the logfile?</p>
  
  <p>I think I want to unite the members of lstGroupX and lstGroupY such that it looks like AB or BA for all possible 1-to-1 combinations between its members, and then look for AB or BA in the logfile.</p>
  
  <pre><code>//assume the log is in a list called lstLog
  //a list called lstGroupX contains the names GroupX members
  //a list called lstGroupY contains the names GroupY members
  
  var IMBuddies = lstLog.Intersect(lstGroupX).Intersect(lstGroupY);
  </code></pre>
  
  <p>I don't think the above line is quite right.  What I really want is something like this</p>
  
  <pre><code>var IMBuddies = lstLog.Intersect(all possible permutations where lstGroupX members contacts lstGroupY members and vice versa)
  </code></pre>
  
  <p>but I don't know how to do it.</p>