Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EventDriven3a
- {
- public delegate void IntroducedEventHandler(object sender, EventArgs e);
- class Human
- {
- private string name;
- private int age;
- public event IntroducedEventHandler Introduced;
- // public event IntroducedEventHandler Introduced
- // {
- // add { /*...*/ }
- // remove { /*...*/ }
- // }
- public virtual void OnIntroduced(EventArgs e)
- {
- if (Introduced != null)
- {
- Introduced(this, e);
- }
- }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public int Age
- {
- get { return age; }
- set { age = value; }
- }
- public Human(string name, int age)
- {
- this.name = name;
- this.age = age;
- }
- public void IntroduceYourSelf()
- {
- // 1. hard coded
- // OnIntroduceYourSelf();
- // 2. delegate
- // if (Introduced != null) {
- // Introduced(this, EventArgs.Empty);
- // }
- // 3.
- OnIntroduced(EventArgs.Empty);
- Console.WriteLine("I am a human! My name is {0}. I am {1} years old!", name, age);
- }
- private void OnIntroduceYourSelf()
- {
- Console.WriteLine("I am an event handler static!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement