我正在使用 Unity 和 Parse.com 进行游戏开发。我想弄清楚我在保存后立即检索了 objectId。我试过这个:
ParseObject myGame = new ParseObject("Games");
myGame["score"] = 223;
myGame["playerName"] = "Michael";
Task saveTask = myGame.SaveAsync().ContinueWith(t => {
ParseObject theObject = t.Result;
string newObjectId = theObject.objectId;
});
我在 t.Result 上收到一条错误消息:
Type `System.Threading.Tasks.Task' does not contain a definition for `Result' and no
extension method `Result' of type `System.Threading.Tasks.Task' could be found (are
you missing a using directive or an assembly reference?)
这可以通过这种方式或其他方式完成吗?
感谢任何帮助并提前致谢:-)
最佳答案
我在检索新创建的 ObjectId
时也遇到了问题。几个小时后(以及大量搜索)我能够让下面的代码工作:
public static async Task<string> CreateNewGame()
{
string newObjectId = null;
ParseObject myGame = new ParseObject("Games");
myGame["score"] = 223;
myGame["playerName"] = "Michael";
await myGame.SaveAsync().ContinueWith(
t =>
{
newObjectId = myGame.ObjectId;
});
return newObjectId;
}
关于c# - 如何在保存后立即检索 objectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27248622/