c# - Return Variable From Method -


i know how pass variables procedure, how return variable calling procedure? example, syntax, no issue @ passing in variable arr how can return value nummmm main? please disregard empty sqlconnection & update statement etc, valid in actual syntax.

namespace consoletest {   class test   {     public static string sqlconnectionstring = "";     public static string updatestatement = null;     public static string[] arrarray;     public int       static void main(string[] args)     {         arrarray = new string[3] { "1412", "1618", "1223" };         foreach (string arr in arrarray)         {           runupdates(arr, out nummmm);         }     }      private static int runupdates(string arr, out int nummmm)     {         updatestatement = "";         using (sqlconnection connection = new sqlconnection(sqlconnectionstring))         {             connection.open();             using (sqlcommand command = new sqlcommand(updatestatement, connection))             {             command.commandtext = updatestatement;             int nummmm = command.executenonquery();             connection.close();             }         }     }   } } 

my edited code give compile error of 'not code paths return value.

just use function return value. not need additional output parameter.

private static int runupdates(string arr) {     updatestatement = "";     using (sqlconnection connection = new sqlconnection(sqlconnectionstring))     {         connection.open();         using (sqlcommand command = new sqlcommand(updatestatement, connection))         {         command.commandtext = updatestatement;         int nummmm = command.executenonquery();         connection.close();         }     }     return nummmm; } 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -