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:
App
is null (very unlikely)App.ViewModel
could be null.- The
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.
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
.
精彩评论