Even for a referenct type variable, when you want pass values with a parameter of a function, you still need to use "ref", otherwise, the compiler will treat it as a "local" variable, and won't pass value back from called method.
In following code, the initialization in method FillMessageCommand won't pass back to method GetRejectionMessageCommand with the keyword "ref". The compiler create a new instance of cmd for FillMessageCommand. It has nothing related to the cmd instance in the caller method.
private AseCommand GetRejectionMessageCommand(AseCommand cmd, StringBuilder sidList)
{
// it doesn't support parameter for the sidList as list
string sqlCommand = @" SELECT message_text, sid, user_id, update_date
FROM dbo.ExceptionMessage
WHERE sid IN (" + sidList + @")
UNION
SELECT message_text, sid, user_id, update_date
FROM dbo.RemovalMessage
WHERE sid IN (" + sidList + @")
UNION
SELECT message_text, sid, user_id, update_date
FROM dbo.VerifyMessage
WHERE sid IN (" + sidList + @")
ORDER BY sid ASC, update_date DESC";
FillMessageCommand(ref cmd, sidList, sqlCommand);
return cmd;
}
private void FillMessageCommand(ref AseCommand cmd, StringBuilder sidList, string sqlCommand)
{
cmd =initializeIrisPrimaryDB(sqlCommand);
cmd.CommandType = CommandType.Text;
}
No comments:
Post a Comment