List.clear() followed by List.add() not working.

Posted by Vincent on Stack Overflow See other posts from Stack Overflow or by Vincent
Published on 2010-12-27T18:43:52Z Indexed on 2010/12/27 18:54 UTC
Read the original article Hit count: 122

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ