컴파일러 오류 CS0079

업데이트: 2007년 11월

오류 메시지

'event' 이벤트는 += 또는 -=의 왼쪽에만 사용할 수 있습니다.
The event 'event' can only appear on the left hand side of += or -=

event를 잘못 호출했습니다. 자세한 내용은 이벤트(C# 프로그래밍 가이드)대리자(C# 프로그래밍 가이드)를 참조하십시오.

다음 샘플에서는 CS0079 오류가 발생하는 경우를 보여 줍니다.

// CS0079.cs
using System;

public delegate void MyEventHandler();

public class Class1
{
   private MyEventHandler _e;

   public event MyEventHandler Pow
   {
      add
      {
         _e += value;
         Console.WriteLine("in add accessor");
      }
      remove
      {
         _e -= value;
         Console.WriteLine("in remove accessor");
      }
   }

   public void Handler()
   {
   }

   public void Fire()
   {
      if (_e != null)
      {
         Pow();   // CS0079
         // try the following line instead
         // _e();
      }
   }

   public static void Main()
   {
      Class1 p = new Class1();
      p.Pow += new MyEventHandler(p.Handler);
      p._e();
      p.Pow += new MyEventHandler(p.Handler);
      p._e();
      p._e -= new MyEventHandler(p.Handler);
      if (p._e != null)
      {
         p._e();
      }
      p.Pow -= new MyEventHandler(p.Handler);
      if (p._e != null)
      {
         p._e();
      }
   }
}