Pass a Cast by Reference

  • Thread starter Thread starter David Martin
  • Start date Start date
D

David Martin

I am working with some third part code. The method in question has the
following signature:

public sub Add(ByVal ObjProperty as String, ByRef ctrl as
System.Windows.Forms.Controls)

The problem is that I need to pass a control that is not in the
System.Windows.Forms.Controls namespace. It is an Infragistics control.

In the past, using VB.net, I have been able to call the above method with
this:

controlbinder.Add("Name", DirectCast(txtName, Control))

Now I need to be able to do this same thing from C#. I have tried

controlbinder.Add("Name", (Control) txtName);

and

controlbinder.Add("Name", ref txtName);

and

controlbinder.Add("Name", ref (Control) txtName);

Any help would be greatly appreciated.
David Martin
 
Thanks. For some reason I was hesitant to try that as I have many controls
on the form and didn't want to create duplicates with:
Control tmp1 = txtName;
Control tmp2 = txtAddress;

But, once I saw your reply I tried it anyway using just one variable: tmp.
And it works. Thanks.
 
Back
Top