title: c# check for a poker straight
body: <p>I am trying to write a poker hand evaluation method in c#. I have managed to do this for every poker hand using linq except a straight. 
  For those that don't play a straight is made up of 5 cards with increments of 1 for each card. Ace can be high or low. </p>
  
  <p>I have created an object called card which has a suit, rank and value (J = 11, Q =12 etc..). My method will be passed a list of this object containing 7 cards (hole cards and the board.) </p>
  
  <p>Another thing to bear in mind is that a straight can only be made if the player has a 5 or 10. </p>
  
  <p>See below my methods for other poker hands and please let me know if you have an idea for the straight method. Pseudo code would be fine also.</p>
  
  <hr>
  
  <pre><code>public bool CheckPair(List&lt;Card&gt; cards)
  {
      //see if exactly 2 cards card the same rank.
      return cards.GroupBy(card =&gt; card.Rank).Count(group =&gt; group.Count() == 2) == 1;
  }
  
  public bool CheckTwoPair(List&lt;Card&gt; cards)
  {
      //see if there are 2 lots of exactly 2 cards card the same rank.
      return cards.GroupBy(card =&gt; card.Rank).Count(group =&gt; group.Count() &gt;= 2) == 2;
  }
  
  public bool CheckTrips(List&lt;Card&gt; cards)
  {
      //see if exactly 3 cards card the same rank.
      return cards.GroupBy(card =&gt; card.Rank).Any(group =&gt; group.Count() == 3);
  }
  public bool CheckStraight(List&lt;Card&gt; cards)
  {
      // order by decending to see order
      var cardsInOrder = cards.OrderByDescending(a =&gt; a.Value).ToList();
      // check for ace as can be high and low
      if (cardsInOrder.First().Rank == "A")
      {
          // check if straight with ace has has 2 values
          bool highStraight = cards.Where(a =&gt; a.Rank == "K" || a.Rank == "Q" || a.Rank == "J" || a.Rank == "10").Count() == 4;
          bool lowStraight = cards.Where(a =&gt; a.Rank == "2" || a.Rank == "3" || a.Rank == "4" || a.Rank == "5").Count() == 4;
          // return true if straight with ace
          if (lowStraight == true || highStraight == true)
          {
              return true;
          }
      }
      else
      {
          // check for straight here
          return true;
      }
      // no straight if reached here.
      return false;
  
  }
  
  public bool CheckFlush(List&lt;Card&gt; cards)
  {
      //see if 5 or more cards card the same rank.
      return cards.GroupBy(card =&gt; card.Suit).Count(group =&gt; group.Count() &gt;= 5) == 1;
  }
  
  public bool CheckFullHouse(List&lt;Card&gt; cards)
  {
      // check if trips and pair is true
      return CheckPair(cards) &amp;&amp; CheckTrips(cards);
  }
  public bool CheckQuads(List&lt;Card&gt; cards)
  {
      //see if exactly 4 cards card the same rank.
      return cards.GroupBy(card =&gt; card.Rank).Any(group =&gt; group.Count() == 4);
  }
  
  // need to check same 5 cards
  public bool CheckStraightFlush(List&lt;Card&gt; cards)
  {
      // check if flush and straight are true.
      return CheckFlush(cards) &amp;&amp; CheckStraight(cards);
  }
  </code></pre>