Exemplo n.º 1
0
        //Inheritance and objects
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Person objP1;
                /* You cannot make a person object when the class is marked abstract. */
                //objP1 = new Person();


                /* But, can you make a variable of the abstract class that points to a object? */
                objP1 = new Employee();
                //or
                objP1 = new Customer();

                //This connects the event to a method
                objP1.NameChanged += new EventHandler(objP1_NameChanged);

                //Set the properties
                objP1.Name = "Bob Smith";
                objP1.DOB = Convert.ToDateTime("01/01/1980");
                objP1.Gender = Gender.Male;

                //Use a method
                MessageBox.Show(objP1.GetData());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        //a more typical way to create a customer object        
        private void button2_Click(object sender, EventArgs e)
        {
            Customer objC1 = new Customer();
            objC1.CustomerId = 1;
            objC1.Name = "Sue Jones";
            objC1.DOB = DateTime.Parse("1/1/1980");
            objC1.Gender = Gender.Female;

            MessageBox.Show(objC1.GetData());
        }