I want to use the FindAll
method in C# in like this:
List<Card> cards = new List<Card>();
cards.AddRange(testCaseCards);
Console.WriteLine(cards.Count);
List<List<Card>> cardsSuits = new List<List<Card>>();
List<Card> tempList = new List<Card>();
for (int i = 0; i < 4; ++i)
{
Console.WriteLine(cards[i].Suit);
tempList = cards.FindAll(card => card.Suit == (Suit)i);
cardsSuits.Add(tempList);
}
When I initialize my code with testCaseCards
containing 9 cards, everything works just fine up until the FindAll
query. The value of cards.Count
is 9 and cards[i].Suit
returns the respective suits.
But when FindAll
executes it throws an exception that "card
was null" and I'm looking for a way to step into the FindAll
as it goes through the cards and set a breakpoint to examine values and determine the exact cause of failure. I looked at this answer which mentions Linq
in passing but doesn't provide any real guidance about debugging a null exception while the Linq
query is running.
Also, if you notice any other problems in my code please point them out.