컴파일러 오류 CS0070

업데이트: 2007년 11월

오류 메시지

'event' 이벤트는 += 또는 -=의 왼쪽에만 사용할 수 있습니다. 단 이 이벤트가 'type' 형식에서 사용될 때는 예외입니다.
The event 'event' can only appear on the left hand side of += or -= (except when used from within the type 'type')

event는 이것이 정의된 클래스의 외부에서 참조를 더하거나 뺄 수만 있습니다. 자세한 내용은 이벤트(C# 프로그래밍 가이드)를 참조하십시오.

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

// CS0070.cs
using System;
public delegate void EventHandler();

public class A
{
   public event EventHandler Click;

   public static void OnClick()
   {
      EventHandler eh;
      A a = new A();
      eh = a.Click;
   }

   public static void Main()
   {
   }
}

public class B
{
   public int Foo ()
   {
      EventHandler eh = new EventHandler(A.OnClick);
      A a = new A();
      eh = a.Click;   // CS0070
      // try the following line instead
      // a.Click += eh;
      return 1;
   }
}