List.clear() followed by List.add() not working.
- by Vincent
I have the following C# Class/Function:
class Hand
{
private List<Card> myCards = new List<Card>();
public void sortBySuitValue()
{
IEnumerable<Card> query = from s in myCards
orderby (int)s.suit, (int)s.value
select s;
myCards = new List<Card>();
myCards.AddRange(query);
}
}
On a card Game. This works fine, however, I had trouble at first, instead of using myCards = new List(); to 'reset' myCards, I would use myCards.clear(), however, once I called the clear function, I would not be able to call myCards.add() or myCards.addRange(). The count would stay at zero. Is my current approach good? Is using LINQ to sort my cards good/bad?