Is there any practical difference in terms of effects on the component model between:
class MyComponent : Component {
public MyComponent() {
InitializeComponent();
}
public MyComponent(IContainer container) {
container.Add(this);
InitializeComponent();
}
}
and:
class MyComponent : Component {
public MyComponent() {
InitializeComponent();
}
public MyComponent(IContainer container) : this() {
container.Add(this);
}
}
and if not, why did Microsoft pick the first method for their designer-generated code?
Edit: What I mean is, will there be any side effects towards the change of order between initializing the component and adding it to the container?
Order of execution differs. In
public MyComponent(IContainer container) {
container.Add(this);
InitializeComponent();
}
InitializeComponent() is executed after container.Add(), whereas here
public MyComponent(IContainer container) : this() {
container.Add(this);
}
container.Add() is executed after InitializeComponent()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With