【发布时间】:2015-02-12 12:09:21
【问题描述】:
为什么我在尝试清除可观察集合的值时收到错误“对象引用未设置为对象的实例”?
if(testcollection.Count>0) testcollection.Clear();
【问题讨论】:
为什么我在尝试清除可观察集合的值时收到错误“对象引用未设置为对象的实例”?
if(testcollection.Count>0) testcollection.Clear();
【问题讨论】:
根据您提供的有限代码,当您尝试访问计数时,testcollection 似乎为空。试试这个:
if (testcollection != null && testcollection.Count > 0) testcollection.Clear();
【讨论】: