CSE459_CSharp_04_Events

CSE459_CSharp_04_Events - Programming in C# Events Events...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Programming in C# Events Events CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis The event field An event field is just a special delegate instance. Usually exposed as a public field (acts more like a property). Restricts the delegate operations (to the public) to += and -=. Only the class (or its decendents) can fire the event. Only the class (or its descendents) can clear or reset the values (using =). Published Properties public class SharedFloat { public delegate void NewValue ( float value); public event NewValue ValueChanging; public event NewValue ValueChanged; private void Dummy( float value) {} public SharedFloat() { // This avoids the check for null. ValueChanging += Dummy; ValueChanged += Dummy; } } private float myFloat; public float Value { get { return myFloat; } set { ValueChanging( value ); myFloat = value ; ValueChanged(myFloat); } } Example class Model { public event Notifier notifyViews ; public void Change() { ... notifyViews ("Model"); } } class View { public View(Model m) { m.notifyViews += new Notifier(Update); } void Update(string sender) { Console.WriteLine(sender + " was changed"); }void Update(string sender) { Console....
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 12

CSE459_CSharp_04_Events - Programming in C# Events Events...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online