c# - Is it possible to use Task<bool> in if conditions? -


in windows phone 8 have method public async task<bool> authentication(). return type of function bool when tried use returned value in if condition error says can not convert 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; } 

the return type of function task<bool>, not bool itself. result, should use await keyword:

bool result = await authentication(); 

you can read "what happens in async method" section of msdn article more understanding on async / await language feature.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -