检查可观察集合是否为空!时间:2019-03-17 标签:c#
想要检查名为 PlayerProfile
if ((App.ViewModel.PlayerProfile.Count != 0))
{
// remove stored PlayerProfile
}
Anyideas 的可观察集合中是否有 ant Items ?
gettign 一个空错误(即使有
App.ViewModel.PlayerProfile 是一个可观察的包含玩家的集合,
我只想检查它是否为空,如果不删除或清除
want to check if there are ant Items in an observable collection named PlayerProfile
if ((App.ViewModel.PlayerProfile.Count != 0))
{
// remove stored PlayerProfile
}
Anyideas ??
gettign a null error (even though there are
App.ViewModel.PlayerProfile is an oberservable collection containg players
i just want to check to see if its empty and if not delete or clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您收到 null 错误,则存在三种可能性:
App
为 null(极不可能)App.ViewModel
可能为 null。ViewModel
上的PlayerProfile
属性可能为 null。我建议确保在 ViewModel 的所有构造函数中构造
PlayerProfile
,并且此时您的 ViewModel 已构造完毕,因为这些是最有可能的罪魁祸首。最有可能的是,该例程在初始化方法之前被调用,这就是此时未设置这些例程的原因。If you're getting a null error, there are three possibilities:
App
is null (very unlikely)App.ViewModel
could be null.PlayerProfile
property onViewModel
may be null.I suggest making sure that
PlayerProfile
is being constructed in all constructors of your ViewModel, and that your ViewModel has been constructed at this point, as those are the most likely culprits. Most likely, this routine is being called prior to your initialization methods, which is why these are unset at this point.Count
属性将返回集合中元素的数量。但是,如果您收到 null 错误,则意味着某些内容为 null。
The
Count
property will return the number of elements in the collection.However, if you're getting a null error, that means something is null.
App
、ViewModel
或PlayerProfile
为null
。Either
App
,ViewModel
orPlayerProfile
isnull
.