If I have a default initializer set, and a define an anonymous one when I create my object. Is the default skipped, or just run before? The reason I want to know is because in the case below, if they are run after, the List object created in the default will be discarded immediately, thus creating unnecessary garbage.
class ArrangedPanel : RectElement
{
public List<RectElement> arrangedChildren = new List<RectElement>();
public int Padding = 2;
}
//Somewhere else
new ArrangedPanel()
{
Padding = 5,
arrangedChildren = new List<RectElement>()
{
new ButtonToggle(),
new ButtonToggle()
}
}
In your example code the
Padding = 2occurs beforePadding = 5.You are unnecessarily creating a
List<RectElement>, but I’d challenge you to create a scenario where such unnecessary allocations cause any appreciable performance hit.