Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program.cs
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var instance = new DerivedClass();
- instance.Init();
- instance.DoSomething(); // outputs "DerivedClass"
- }
- }
- class EventSource
- {
- public event EventHandler SomeEvent;
- public void DoSomething()
- {
- if (this.SomeEvent != null) this.SomeEvent(this, EventArgs.Empty);
- }
- }
- class BaseClass
- {
- private readonly EventSource _source = new EventSource();
- public void Init()
- {
- _source.SomeEvent += _source_SomeEvent;
- }
- protected virtual void _source_SomeEvent(object sender, EventArgs e)
- {
- Console.WriteLine("BaseClass");
- }
- public void DoSomething()
- {
- _source.DoSomething();
- }
- }
- class DerivedClass : BaseClass
- {
- protected override void _source_SomeEvent(object sender, EventArgs e)
- {
- Console.WriteLine("DerivedClass");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement