c# - Compensating for the lack of 'out' parameters in async methods. -


i have class handles api transactions in application i'm working on. general outline methods this:

public static async task<bool> apicall(int bla)         {             httpresponsemessage response;             bool res;              // post/getasync server depending on call + other logic             return res;         } 

what want able return response.statuscode caller, since not allowed use 'out' parameters async methods complicates things bit.

i thinking returning tuple containing both bool , response code, there better way this?

i thinking returning tuple containing both bool , response code, there better way this?

you create specific class hold results. don't tuples, because names item1 or item2 nothing values.

class apicallresult {     public bool success { get; set; }     public httpstatuscode statuscode { get; set; } }      public static async task<apicallresult> apicall(int bla)     {         httpresponsemessage response;         bool res;          // post/getasync server depending on call + other logic         return new apicallresult { success = res, statuscode = response.statuscode };     } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -