I know how to pass variables to a procedure, but how do I return a variable to the calling procedure? For example, this is my syntax, no issue at all passing in the variable arr
but how can I return the value nummmm
back to Main
? Please disregard the empty sqlconnection & update statement etc, they are valid in my 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 now give a compile error of 'Not All Code Paths return a value.
Just use the function itself to return the value. You do not need an additional output parameter.