The argument argument is not classified as a variable - is it better for this?

I have this piece of code that has been converted from VB.NET.

    private static void PrivateExecuteNonQuery(ref Providers enumProvider, ref string statement, ref CommandType commandType, ref ArrayList paramCollection, ref IDbConnection conn, ref Int16 CommandTimeout)
    {
        ExecuteSqlServerNonQuery(ref statement, ref commandType, ref paramCollection, ref (SqlConnection)conn, ref CommandTimeout);
    }

I get an error because it says that the ref (SqlConnection) link is not in the form of a variable, so I think you can not pass the method parameters for the link?

So this seems like a hacker solution for me:

    private static void PrivateExecuteNonQuery(ref Providers enumProvider, ref string statement, ref CommandType commandType, ref ArrayList paramCollection, ref IDbConnection conn, ref Int16 CommandTimeout)
    {
        SqlConnection sqlConnection = (SqlConnection)conn;

    ExecuteSqlServerNonQuery(ref statement, ref commandType, ref paramCollection, ref sqlConnection, ref CommandTimeout);
    }

Does anyone know a better way to satisfy this issue or make this cleaner?

+3
source share
1 answer

purpose ref- Actually allow the method to modify the contents of the variable passed to the caller. If you have random ref parameters, due to the conversion from the Visual Basic code that you used ByRefindiscriminately, you fall into this situation.

:

  • ref, , ,
  • , , ,

, : , , ref .

ref ? , . ref, , , .

+12

All Articles