问题
I have a wpf application. when I run it it close. I debugged it and I found that this linq query close it(I don't know why!)
TodayCards = cards.Where(i => (i.NextTime.Day == DateTime.Now.Day && i.NextTime.Month == DateTime.Now.Month && i.NextTime.Year == DateTime.Now.Year)).Select(i => i).ToList();
I also tried
TodayCards = cards.Where(i => (i.NextTime.Day == DateTime.Now.Day && i.NextTime.Month == DateTime.Now.Month && i.NextTime.Year == DateTime.Now.Year)).ToList();
but it closed it both situations.
回答1:
Most likely NextTime
is null
on at least one card or cards
itself is null
.
回答2:
I found out why!
cards
was null and it close my application. I put this code before my linq query:
foreach (var item in cards)
{
if (item.NextTime == null)
{
int a = 0;
}
}
to find if there is any null next time but it closes before run and I found out the problem is card
. I can't still say why it close the app without any exceptions but the problem resolved!
来源:https://stackoverflow.com/questions/12509607/linq-query-close-my-wpf-application