我正在尝试在IsolatedStorageSettings中保存一个对象以保存我的游戏的高分,但每当我尝试保存对象的更新副本时,C#似乎认为对象没有改变。我尝试为HighScores类创建一个自定义的Equals函数,但这似乎没有帮助。
知道我做错了吗?
谢谢
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;
}
答案 0 :(得分:2)
您尚未实现等于运算符'=='和'!='并且这些比较引用相等,您将提供映射到'Equals'方法的实现
http://msdn.microsoft.com/en-us/library/ms173147%28v=vs.80%29.aspx
答案 1 :(得分:0)
您应该使用isolatedStore.Save()来提交更改