Created
January 17, 2017 17:59
-
-
Save deepumi/17a251f156d90217b248b6d0b527e74d to your computer and use it in GitHub Desktop.
Event Hanlder
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
class C | |
{ | |
public event EventHandler<EventArgs> ItemDiscarded; | |
public void Add(int value) | |
{ | |
OnItemDiscarded(value);//trigger event handler | |
} | |
void OnItemDiscarded(int value) | |
{ | |
if (ItemDiscarded != null) | |
{ | |
var arg = new ItemDiscardedEventArgs(value); | |
ItemDiscarded(this, arg); | |
} | |
} | |
} | |
public class ItemDiscardedEventArgs : EventArgs | |
{ | |
public int ItemDiscarded {get; set;} | |
public ItemDiscardedEventArgs(int item) | |
{ | |
ItemDiscarded = item; | |
} | |
} | |
static void Main() | |
{ | |
C c = new C(); | |
c.ItemDiscarded += OnItemDiscarded; ; | |
c.Add(5); | |
} | |
private void OnItemDiscarded(object sender, EventArgs e) | |
{ | |
var a = e as ItemDiscardedEventArgs; | |
var value = a.ItemDiscarded; | |
} | |
//Covariance = <out T> returns output (Manager -> Employe -> Person) ex: FindAll() or FindById | |
//Contravariance = <in T> input (Manager -> Employe -> Person) ex:Create(),Save(),Commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment