I'm not able to save to the isolated storage?

后端 未结 2 1160
遇见更好的自我
遇见更好的自我 2021-01-28 11:38

I\'m trying to save my model in isolated storage:

var settings = IsolatedStorageSettings.ApplicationSettings;

CurrentPlaceNowModel model = new CurrentPlaceNowMo         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 12:31

    I've just noticed what you've done wrong:

    if (model == null)
    {
        MessageBox.Show("NULL");
        settings.Add("model", model);
    }
    

    That's going to be equivalent to calling settings.Add("model", null) - so how would you expect to get a non-null value out later? I suspect you want:

    CurrentPlaceNowModel model;
    
    if (!settings.TryGetValue("model", out model))
    {
        model = new CurrentPlaceNowModel();
        settings.Add("model", model);
    }
    

提交回复
热议问题