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 EventDriven1a
- {
- public delegate void IntroducedEvenetHandler(object sender, EventArgs e);
- class Human
- {
- private string name;
- private int age;
- public event IntroducedEvenetHandler Introduced;
- 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;
- }
- protected virtual void OnIntroduced(EventArgs e)
- {
- if (Introduced != null)
- {
- Introduced(this, e);
- }
- }
- public void IntroduceYourSelf()
- {
- // 1. Approach
- // OnIntroduce();
- // 2. delegates
- // if (Introduced != null) {
- // Introduced(this, EventArgs.Empty);
- // }
- // 3 with a special method
- OnIntroduced(EventArgs.Empty);
- Console.WriteLine("I am human. My name is {0}. I am {1} years old!", name, age);
- }
- private void OnIntroduce()
- {
- Console.WriteLine("================ IntroduceYourSelf was executed!!! ================");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement