Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <a href="http://msdn.microsoft.com/en-us/library/bb460136.aspx" rel="nofollow"><code>Intersect()</code></a> to find the items that two collections have in common, and then apply <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.count.aspx" rel="nofollow"><code>Count()</code></a> to see if the intersection has at least three items:</p> <pre><code>var winners = players. Where(player =&gt; player.Numbers.Intersect(lotto).Count() &gt;= 3); </code></pre> <p>A couple of notes on your implementation:</p> <ul> <li>Rather than using a <code>Dictionary</code> and setting values to <code>1</code>, use a <code>HashSet</code>: you are interested in keys, not values, so a <code>Set</code> would be more appropriate</li> <li>Do not convert numbers to strings until you need to display them; searching for numbers is best done with a collection of numbers.</li> <li>If you use a set, the selection can be rewritten as follows:</li> </ul> <hr/> <pre><code>var lotto = new HashSet&lt;int&gt;(...); // put six numbers here var winners = players. Where(player =&gt; player.Numbers.Where(n =&gt; lotto.Contains(n)).Count() &gt;= 3); </code></pre> <p><strong>EDIT :</strong> (in response to an edit of the question) Your <code>Player</code> class contains player's numbers as separate attributes. You can add a way of retrieving them as a collection by adding a property <code>Numbers</code>, like this:</p> <pre><code>class Player { ... public int val0, val1, val2, val3, val4, val5, val6; public IEnumerable&lt;int&gt; Numbers { get { return new[] {val0, val1, val2, val3, val4, val5, val6}; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload