Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a complete demo sample that demostrates required behaviour.</p> <p>For the sake of ease your learning, I chose a <strong>string</strong> type parameter that you adjust to your case.</p> <p>To test it, create a new <strong>Visual Studio</strong> *<em>C#</em>* project and fill <strong>program.cs</strong> with the following code</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Stackoverflow { public class ClassA : Form { public ClassA() { InitializeComponent(); } public ClassA(string WindowTitleParameter) { InitializeComponent(); this.Text = WindowTitleParameter; MessageBox.Show("Hi! I am ClassB constructor and I have 1 argument. Clic OK and look at next windows title"); } private void InitializeComponent() // Usually, this method is located on ClassA.Designer.cs partial class definition { // ClassA initialization code goes here } } public class ClassB : ClassA { // The following defition will prevent ClassA's construtor with no arguments from being runned public ClassB(string WindowTitleParameter) : base(WindowTitleParameter) { InitializeComponent(); //this.Text = WindowTitleParameter; //MessageBox.Show("Hi! I am ClassB constructor and I have 1 argument. Clic OK and look at next windows title"); } private void InitializeComponent() // Usually, this method is located on ClassA.Designer.cs partial class definition { // ClassB initialization code goes here } } static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // If you debug this code using StepInto, you will notice that contructor of ClassA (argumentless) // will run prior to contructor of classB (1 argument) Application.Run(new ClassB("Look at me!")); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload