simple one on out parameters in functions

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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);
 
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.
 
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
 
Back
Top