Click to See Complete Forum and Search --> : How to I acheve the same effect as &(int) in C#


savagerx
February 6th, 2003, 12:20 PM
In C++, we can do this,
void SomeFunctions(int &a){...}

But in C#, I used,
public SomeFunctions(ref int a) and the compiler says invalid argument.
i.e.
...
int x=0;
SomeFunctions(x);
...

Then I tried this,
public SomeFunction(ref Object a) and the compiler says cannot convert Object from int.
I thought C# is able to auto-box int to an Object?

So now, I'm jammed here, how should I proceed?

pareshgh
February 6th, 2003, 12:29 PM
no u keep method as it is
and pass as

SomeMethodCall(ref a) ;
like that

Paresh

pareshgh
February 6th, 2003, 07:43 PM
forgot to mention

public void DrawAppointment(ref int abc)
{
x = x * x;
}

would be called as

int x = 10;
DrawAppointment(ref x);

now x will have 100;

Paresh

savagerx
February 6th, 2003, 09:30 PM
Oh my GOD! I can't believe I'm making such a careless mistake!:eek:

I called using "someFunctions(x)" where it should be "SomeFunctions(ref x)".

Thanks for the enlightenment.

pareshgh
February 7th, 2003, 11:05 AM
no probs...
it happens.. but if you are compiling programs then you should check some syntaxes here and there. .since its just matter of testing ... :-)

Paresh