-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kody Brown
committed
Feb 11, 2013
1 parent
32bd45f
commit d868712
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
EssentialCSharp/Chapter13/Listing13.17.CSharpConceptualEquivalentOfEventCILCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_17 | ||
{ | ||
using System; | ||
|
||
public class Thermostat | ||
{ | ||
// ... | ||
// Declaring the delegate field to save the | ||
// list of subscribers. | ||
private EventHandler<TemperatureArgs> _OnTemperatureChange; | ||
|
||
public void add_OnTemperatureChange( | ||
EventHandler<TemperatureArgs> handler) | ||
{ | ||
System.Delegate.Combine(_OnTemperatureChange, handler); | ||
} | ||
|
||
public void remove_OnTemperatureChange( | ||
EventHandler<TemperatureArgs> handler) | ||
{ | ||
System.Delegate.Remove(_OnTemperatureChange, handler); | ||
} | ||
|
||
//public event EventHandler<TemperatureArgs> OnTemperatureChange | ||
//{ | ||
// //Would cause a compiler error. | ||
// add | ||
// { | ||
// add_OnTemperatureChange(value); | ||
// } | ||
// //Would cause a compiler error. | ||
// remove | ||
// { | ||
// remove_OnTemperatureChange(value); | ||
// } | ||
//} | ||
|
||
public class TemperatureArgs : System.EventArgs | ||
{ | ||
public TemperatureArgs(float newTemperature) | ||
{ | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters