void
void

Reputation: 1896

C# passing this as container reference to class constructor

I want to perform

this.Controls.Add(MyObject)

in the class definition of MyObject like

public MyClass(container/*?*/ con,Point L)
{
con.Controls.Add(this);
}

can I do something like this? thanks.

Upvotes: 3

Views: 331

Answers (1)

Servy
Servy

Reputation: 203828

Control will work just fine.

public void method(Control container)
{
    container.Controls.Add(this);
}

If you pass in a Control that can't actually have children (say, TextBox) it will either do nothing or throw an exception at runtime.

Upvotes: 1

Related Questions