Instantiating Objects from Classes
After you obtain a reference to an object and assign it to a variable, you can manipulate the object using an object variable. You're going to do this now.
Click the Form1.cs Design tab to view the form designer and add a button to the form by double-clicking the Button item in the toolbox. Set the button's properties as follows:
Next, double-click the button to access its Click event and enter the following code:
clsMyClass objMyObject = new clsMyClass(); MessageBox.Show(objMyObject.AddTwoNumbers(1,2).ToString());
The first statement creates a variable of type clsMyClass. (Declaring variables was discussed in Hour 12, “Using ...