title: C# trigger event
body: <p>I use C# and I want to trigger an event from within a class :</p>
  
  <p>So if the <code>Price</code> property of a class was changed then an event <code>onPriceChanged</code> (outside the class)  should be fired.
  However, I get an error:   </p>
  
  <blockquote>
    <p>The name 'onPriceChanged' does not exist in the current context</p>
  </blockquote>
  
  <p>How could I fix this?
  (I guess that I could pass the eventhandler to the class via constructor...but if possible I would prefer not to pass the eventhandler to the class)<br></p>
  
  <p>Here is my code :</p>
  
  <pre><code>using System;
  
  public delegate void delEventHandler();
  
  class clsItem
  {
      //private static event delEventHandler _show;
      private delEventHandler _show;
      private int _price;
  
      public clsItem()  //Konstruktor
      {
          _show += new delEventHandler(Program.onPriceChanged);  //  error here :  The name 'onPriceChanged' does not exist in the current context
      }
  
      public int Price
      {
          set
          {
              _price = value;
              _show.Invoke();  //trigger Event when Price was changed
          }
      }
  }
  
  class Program
  {
      static void Main()
      {
          clsItem myItem = new clsItem();
          myItem.Price = 123;   //this should trigger Event "onPriceChanged"
      }
  
      //EventHandler 
      public static void onPriceChanged()
      {
          Console.WriteLine("Price was changed");
      }
  }
  </code></pre>