Skip to content

Instantly share code, notes, and snippets.

@lai32290
Created March 24, 2018 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lai32290/84eb39905c9acc9b104b75b3ee9b94ea to your computer and use it in GitHub Desktop.
Save lai32290/84eb39905c9acc9b104b75b3ee9b94ea to your computer and use it in GitHub Desktop.
Observer Class
public class Observer<T>
{
public Observer() { }
public Observer(T initValue)
{
value = initValue;
}
private T value;
public T Value
{
get
{
return value;
}
set
{
this.value = value;
if(OnChange != null)
{
OnChange(this.value);
}
}
}
private event ChangeValue OnChange;
public delegate void ChangeValue(T value);
public void Subscribe(ChangeValue subscribe)
{
OnChange += subscribe;
}
public void Unsubscribe(ChangeValue subscribe)
{
OnChange -= subscribe;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment