Passing ref arguements

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
 
M

Miha Markic

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.
 
J

Jon Skeet [C# MVP]

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
 

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