Saturday 15 January 2011

c# - Simulating Events and Delegates in real life scenario -


I would like to teach students about events and representatives with real life example. I would like to associate it with the real life event.

I would like to convert the following real life scenarios into events and representatives.

My heart beats are monitoring. Whenever my heart cracks are abnormal, my doctor will be notified with me the unusual heart rate.

I want to write a code in C # 4.0 so that it can be recorded in events and representatives.

Help is highly appreciated.

You can use the following code:

  class MyHeartBeatMonitor {Public Event EventHandler & lt; Unusual HireRateSimulation & gt; Abnormalheartbeats; Public Zero NotifyFamilyDoctor () {EventHandler & amp; Liberation; Unusual HireartSimulation & gt; Handler = unusual hibbbts; If (Handler! = Null) {Unusual HartRate Simulation Simulate Rates = New Unusual Hart Rate Simulation (); SimulatedRates.heartRate = 140; Handler (this, simulated rates); }}} Public Class Unusual Hartet Simulation: EventArgues {Public Int Heart Rate {Received; Set; }} Category FamilyDoctor {Public Zero Event Handler (Object Sender, Unusual Heart Rate Simulation ARG) {Console.WriteLine ("Heart of Your Patient" is ARG Heart Rate); }} Class program {static zero main (string [] args) {MyHeartBeatMonitor Monitor = New MyHeartBeatMonitor (); Family doctor doctor = new family doctor (); Monitor. Unusual Celebrities + Doctor = Avent Handler; Monitor.NotifyFamilyDoctor (); Console.ReadKey (right); }}   

Go ahead and customize it based on your needs. Good luck!

No comments:

Post a Comment