在 Windows Phone 8 中,我有一个名为 public async Task<bool> authentication()
的方法。该函数的返回类型是 bool
,但当我尝试在 if
条件语句中使用其返回值时,错误提示显示无法将 Task<bool>
转换为 bool
。
public async Task<bool> authentication()
{
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string> ("user", _username),
new KeyValuePair<string, string> ("password", _password)
};
var serverData = serverConnection.connect("login.php", pairs);
RootObject json = JsonConvert.DeserializeObject<RootObject>(await serverData);
if (json.logined != "false")
{
_firsname = json.data.firsname;
_lastname = json.data.lastname;
_id = json.data.id;
_phone = json.data.phone;
_ProfilePic = json.data.profilePic;
_thumbnail = json.data.thumbnail;
_email = json.data.email;
return true;
}
else
return false;
}
Task<bool>
不是bool
。你应该发布你实际遇到问题的代码,但你可能可以这样做:bool b = await authentication(); if(b) { ... }
- Lee