Quote Originally Posted by iRoN_RoCK View Post
How to sort cards in a hand? Can we use LINQ?
vb.net Code:
  1. Dim cards = From c In myHand.Cast(Of Card)() _
  2.             Order By c.Suit, c.Face _
  3.             Select c
That will give you a sorted sequence but it doesn't change the Hand itself. For that you'd have to clear out all the existing Cards and add them all again from the sequence. This code is a bit long in the tooth now anyway so a bit of updating would be in order. For a start, I'd look at inheriting Hand from Collection(Of Card) rather than CollectionBase. I would also add a constructor that would allow creation directly from a list of Cards, which you could get from your LINQ query. You could also have the Card type implement IComparable and then an array or collection could be sorted automatically.