linq query close my wpf application

2019-09-16 19:19发布

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.

2条回答
ゆ 、 Hurt°
2楼-- · 2019-09-16 19:33

Most likely NextTime is null on at least one card or cards itself is null.

查看更多
你好瞎i
3楼-- · 2019-09-16 19:42

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!

查看更多
登录 后发表回答