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
Post a Comment