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 so follow these steps:
Click the Form1.cs Design tab to view the Form Designer.
Add a button to the form by double-clicking the Button item in the toolbox. Set the button's properties as follows:
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 ...