say I have two constructors for a windows form
Sub New (byref Foo as Foo)
InitializeComponent()
...do some work
End Sub
and
Sub New (byref Foo as Foo, Bar as Bar)
InitializeComponent()
_bar = Bar
Me.New(Foo)
End Sub
When using the second constructor, InitializeComponent is called twice. Is that OK? Should I try and prevent it? How?
You might say I could eliminate it from the second constructor, but is it OK for me to start making assignments (like _bar = Bar) before calling InitializeComponent?
Are there any guidelines on what you should or shouldn’t do before calling InitializeComponent? Or is it just safe to call it twice without any real consequences?
Cheers!
Call
InitializeComponentonly in deepest constructor (with biggest number of parameters). And then chain other constructors to call this constructor and provide default values for missing parameters.Here is C# example
I believe in VB it will look like this