I have a question regarding raising base class events. I am currently reading the C # MSDN Programming Guide, and I cannot understand one thing from the following article:
http://msdn.microsoft.com/en-us/library/vstudio/hy3sefw3.aspx
public void AddShape(Shape s) { _list.Add(s); s.ShapeChanged += HandleShapeChanged; }
OK, so we register the delegate with the event, and when the event is called, the private HandleShapeChanged method will be called.
public void Update(double d) { radius = d; area = Math.PI * radius * radius; OnShapeChanged(new ShapeEventArgs(area)); } protected override void OnShapeChanged(ShapeEventArgs e) { base.OnShapeChanged(e); }
And here we call the OnShapeChanged base class method, which, if successful, will fire the event. But the event is based on the Shape class, so how can it access the HandleShapeChanged method, which is private?
I just started to learn the language, so please carry me. My understanding of this example may not be practical.
Kapol source share