title: abstract class event c#
body: <p>I'm trying to raise events in my abstract class and my derived class and have them come out to the same event in main.  Is this possible?  With the code below, I set a breakpoint in the two raise events and I see the bar raise but never the foo and the actual event in main is never called due to OnDataReceived being null.  What am I doing wrong?  If I try to make the bar event abstract and the Raise Function virtual in bar and override both in my derived classes then I get an error for the OnDataReceived in bar not being left side of += or -=.</p>
  
  <p>Here is basically what I have:</p>
  
  <pre><code>public abstract class bar
  {
      public event DataReceivedHandler OnDataReceived;
  
      protected void RaiseDataReceivedEvent(EventArgs e)
      {
          if (OnDataReceived != null)
              OnDataReceived(this, e);
      }
  
      /// &lt;summary&gt;
      /// A global event that will happen for all "bar" derived classes
      /// &lt;/summary&gt;
      private void globalEvent()
      {
          //Raise this event for the derived class here.
          RaiseDataReceivedEvent(new EventArgs());
      }
  }
  
  public class foo : bar
  {
      public foo()
      {
  
      }
  
      /// &lt;summary&gt;
      /// A specific event that will happen only for this derived class
      /// &lt;/summary&gt;
      private void fooSpecificEvent()
      {
          //Raise this event for the derived class here
          RaiseDataReceivedEvent(new EventArgs());
      }
  }
  
  public class Main
  {
      bar specificProduct = new foo();
  
      public Main()
      {
          specificProduct.OnDataReceived += specificProduct_OnDataReceived;
      }
  
      void specificProduct_OnDataReceived(object sender, IttsDataReceivedEventArgs e)
      {
          //Here I want to process events from both fooSpecificEvent and globalEvent calls to RaiseDataReceivedEvent
      }
  }
  </code></pre>