out parameters

  • Thread starter Thread starter mike parr
  • Start date Start date
M

mike parr

I've been using out parameters to return more than 1 value from my
functions. But how do you return a variable that you have passed to the
function originally? The code below doesn't work, do I just change the
name of the variable I am passing back, or is there some clever way to
do this in C#?

private DBResult Change_CC_State(out int intNewStatus, int intNewStatus)
{
//do stuff to intNewStatus before returning
}

Thanks,

Mike
 
mike parr said:
I've been using out parameters to return more than 1 value from my
functions. But how do you return a variable that you have passed to the
function originally? The code below doesn't work, do I just change the
name of the variable I am passing back, or is there some clever way to
do this in C#?

private DBResult Change_CC_State(out int intNewStatus, int intNewStatus)
{
//do stuff to intNewStatus before returning
}

Thanks,

Mike

use this:

private DBResult Change_CC_State(ref int intNewStatus)

(see the "ref") then you can transport values both ways.


Hans Kesting
 
Use "ref" instead. "out" says that the function will supply the variable.
 
The error is the duplicate parameter name.

As far as getting the values. You can just pass in the variable if it's a
reference type or you can pass a value type by ref. "mike parr"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top