simple one on out parameters in functions

G

Guest

i have this in a class:
public void fn_X(out Int32 j)
{
j = 5;
}
i call it by using:

reportFunctionsCS rfcs = new reportFunctionsCS();
Int32 j = 0;
rfcs.fn_X(j);
it always gives me this error:
CS1502: The best overloaded method match for 'reportFunctionsCS.fn_X(out
int)' has some invalid arguments
and i have no idea why, but i'm sure it's simple!!!

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
N

Nicholas Paldino [.NET/C# MVP]

kes,

When you have an "out" parameter, you have to declare out when making
the call as well, like so:

rfcs.fn_X(out j);
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You also have to use the out keyword when you are calling the method, this
is intended to be use as an indication for the calling code that the value
will be modify inside the method.
 
G

Guest

thanks!
This is one of those "Wayne's World, looking at Alice Cooper moments"
"... I was unaware of that..." And in truth i was NOT!

Thank you, very much appreciated
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Nicholas Paldino said:
kes,

When you have an "out" parameter, you have to declare out when making
the call as well, like so:

rfcs.fn_X(out j);


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

WebBuilder451 said:
i have this in a class:
public void fn_X(out Int32 j)
{
j = 5;
}
i call it by using:

reportFunctionsCS rfcs = new reportFunctionsCS();
Int32 j = 0;
rfcs.fn_X(j);
it always gives me this error:
CS1502: The best overloaded method match for 'reportFunctionsCS.fn_X(out
int)' has some invalid arguments
and i have no idea why, but i'm sure it's simple!!!

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 

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

Top