Passing ref arguements

  • Thread starter Thread starter Balamurukan
  • Start date Start date
B

Balamurukan

I have one Interface has one Method namely Showlookup
which has one Ref arguement
Like (ref object ctrl)

I want to pass this as ref Arguement when i call the
method.

I tried ShowLookup(ref this);
It shows an error Like u can not pass this as ref or out
parameter Because it is readonly.
Then i tried
ShowLookup(ref object(this));
Now it Shows an Error Like Ref or out Parameter must have
an lvalue.
Then I tried
object obj=object(this);
ShowLookup(ref obj);

Now it won't show any error.
I don't know wether this one is Right or wrong.

Help me in this regard,

Thanks,
Bala
 
Hi,

You can't use this as ref or out parameter obviously, since this is readonly
reference to current class instance.
You might pass other references though such as your latest example.
 
Balamurukan said:
I have one Interface has one Method namely Showlookup
which has one Ref arguement
Like (ref object ctrl)

I want to pass this as ref Arguement when i call the
method.

I tried ShowLookup(ref this);
It shows an error Like u can not pass this as ref or out
parameter Because it is readonly.
Then i tried
ShowLookup(ref object(this));
Now it Shows an Error Like Ref or out Parameter must have
an lvalue.
Then I tried
object obj=object(this);
ShowLookup(ref obj);

Now it won't show any error.
I don't know wether this one is Right or wrong.

I think you need to be very clear on what ref arguments really are. See
http://www.pobox.com/~skeet/csharp/parameters.html
 
Back
Top