The base constructor does not receive a call

I had a problem when the base constructor for the derived class fails. I have done this a hundred times, and I can’t understand all my life why the base constructor fails. I hope someone finds something simple that I miss. The following is sample code. Does anyone not know why my base constructor is not called first? I have other classes that are implemented the same way, and the base constructor is always called first.

if (item.GetType() == typeof(OtherChargeItem)) { OtherChargeItemAddUpdateTest test = new OtherChargeItemAddUpdateTest((OtherChargeItem)item); test.StartPosition = FormStartPosition.CenterParent; test.ShowDialog(); } public OtherChargeItemAddUpdateTest() { InitializeComponent(); } public OtherChargeItemAddUpdateTest(OtherChargeItem item) : base() { currentItem = item; } 
+6
source share
1 answer

It looks like you want to call the default constructor in the same class, and not in the base class, so InitializeComponent is called when the second constructor is called. Try this() instead of base() .

+22
source

Source: https://habr.com/ru/post/918381/


All Articles