开发者

check to see if an observable collection is empty ! c#

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 开发者_如何学Gooberservable collection containg players

i just want to check to see if its empty and if not delete or clear


If you're getting a null error, there are three possibilities:

  1. App is null (very unlikely)
  2. App.ViewModel could be null.
  3. The PlayerProfile property on ViewModel 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.


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.


Either App, ViewModel or PlayerProfile is null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜