return - c# - Returning Method Results -
return - c# - Returning Method Results -
i new c# programming , trying improve skills using seek grab blocks , improve error handling.
i have class performs mutual task, in case retrieving facebook accesstoken. if successful, want homecoming accesstoken string, if not want homecoming error message. these both strings, no problem. when checking homecoming value on calling side of code, how can effectively?
it's need homecoming 2 values. in case of successful attempt, homecoming = true, "acesscodeacxdjgkeidj", or if fails, homecoming = false, "ooops, there error" + ex.tostring();
then checking homecoming value easy (in theory). think of returning true/false homecoming , setting session variable strings...but not sure best method.
can point me in right direction? best way accomplish this? i'm sure missing elementary.
thanks in advance! chad
create result class , homecoming instead...
public class result { public bool success {get;set;} public string accesstoken {get;set;} public string errormessage {get;set;} } public result getfacebooktoken() { result result = new result(); try{ result.accesstoken = "facebook token"; result.success = true; } catch(exception ex){ result.errormessage = ex.message; result.success = false; } homecoming result; }
then can phone call code like...
result result = getfacebooktoken(); if(result.success) { //do result.accesstoken } else { //do result.errormessage }
c# return
Comments
Post a Comment