我试图保存IsolatedStorageSettings中的对象以保存我的游戏的高分,但每当我尝试保存对象的更新副本C#似乎认为对象没有改变。我试图为HighScores类创建一个自定义的Equals函数,但这似乎没有帮助。使用IsloatedStorageSettings保存自定义对象
任何想法我做错了什么?
感谢
public bool AddOrUpdateValue(string Key, Object value)
{
bool valueChanged = false;
// If the key exists
if (isolatedStore.Contains(Key))
{
// If the value has changed
if (isolatedStore[Key] != value) //This keeps returning false
{
// Store the new value
isolatedStore[Key] = value;
valueChanged = true;
}
}
// Otherwise create the key.
else
{
isolatedStore.Add(Key, value);
valueChanged = true;
}
return valueChanged;
}
//This is located inside the HighScores class
public bool Equals(HighScores newHighScores)
{
for (int i = 0; i < highScores.Length; i++)
{
if (!highScores[i].Name.Equals(newHighScores.GetIndex(i).Name))
{
return false;
}
if (!highScores[i].Time.Equals(newHighScores.GetIndex(i).Time))
{
return false;
}
}
return true;
}
谢谢,我实现==和!=。但它仍然无法正常工作。我在运行Save()之前检查了IsolatedStore的值,并保存了正确的值。但是,当我再次启动应用程序时,这些值不会持续。任何其他想法? – 2011-05-12 08:19:20
所以你可以通过你的代码和'AddOrUpdateValue'按预期工作? – AwkwardCoder 2011-05-12 08:28:27
是的。保存命令是什么似乎是搞砸 – 2011-05-12 20:32:51