accessing variable outside for loop in c#?
<p>Here i need to access the variable <code>delval</code> outside the for loop as in the code below </p>

<pre><code>cmd_mail.Parameters.Add("@deleteusers", SqlDbType.NVarChar).Value = delval;
</code></pre>

<p>..How to do this..    </p>

<p>Here is my code</p>

<pre><code> for (int i = 0; i &lt;= NoOfUsers - 1; i++) {
        using (SqlConnection Conn = new SqlConnection(constr_str)) {
            using (SqlCommand cmd = new SqlCommand()) {
                cmd.Connection = Conn;
                Conn.Open();
                cmd.CommandText = "Select top 1 Login_User_Name  from Rode_Provisioning_User where RequestId=@RequestId and CustomerCode =@CustomerCode and disableflag=0 order by User_Count";
                cmd.Parameters.Add("@CustomerCode", SqlDbType.VarChar).Value = CustomerCode;
                cmd.Parameters.Add("@RequestId", SqlDbType.VarChar).Value = RequestId;
                string Loginusername = cmd.ExecuteScalar();
                Conn.Close();
                string delval = "";
                if (string.IsNullOrEmpty(delval)) {
                    delval = Loginusername;
                } else {
                    delval = delval + "," + Loginusername;
                }
            }
        }
        }

    if (flag == "Yes") {
        string constr_dep = "server=" + _strServer + ";database=" + _strDatabase + ";uid=" + _strUserid + ";pwd=" + _strPassword + ";";
        SqlConnection con_dep = new SqlConnection();
        con_dep.ConnectionString = constr_dep;

        SqlCommand cmd_mail = new SqlCommand("delete_user_mailsend_sp", con_dep);
        cmd_mail.CommandType = CommandType.StoredProcedure;
        cmd_mail.CommandTimeout = 0;
        cmd_mail.Parameters.Add("@companycode", SqlDbType.NVarChar).Value = CustomerCode
        cmd_mail.Parameters.Add("@deleteusers", SqlDbType.NVarChar).Value = delval;
            try {
            con_dep.Open();
            cmd_mail.ExecuteNonQuery();
        } catch (SqlException ee) {
            VWLogger.LogMessage("Exception in delete_user_mailsend_sp:", TraceEventType.Critical);
            VWLogger.LogMessage(ee, TraceEventType.Critical);
            return ee.Message;
            flag = ee.Errors(0).ToString();

        }

        con_dep.Close();
    }
</code></pre>

<p>Any suggestion?</p>
