linq query close my wpf application

为君一笑 提交于 2019-12-13 04:28:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!