June 25, 2008
Hi Guys
NP103 Step not followed
A two-step process creates an object that is an instance of a class. First, you supply a type and an identifier, just as when you declare any variable. Second, you allocate computer memory for that object.
But in the following program first step of supplying a type and an identifier is not followed when creating new SimpleForm(). But program is executing well.
Please explain the reason.
Thank you
using System;
using System.Windows.Forms;
public class SimpleForm : Form
{
private Button button1;
public SimpleForm()
button1 = new Button();
button1.Name = "button1";
button1.Text = "Click Here";
button1.Click += new System.EventHandler(this.button1_Click);
Controls.Add(this.button1);
}
private void button1_Click(object sender, System.EventArgs e)
MessageBox.Show("You clicked the button");
static void Main()
Application.Run(new SimpleForm());