Share via


컴파일러 오류 CS0218

업데이트: 2007년 11월

오류 메시지

'type' 형식에는 true 및 false 연산자 선언이 있어야 합니다.
The type ('type') must contain declarations of operator true and operator false

사용자 정의 형식의 연산자를 정의하여 단락(short-circuit) 연산자로 사용하려면 사용자 정의 연산자에 정의된 true 연산자와 false 연산자가 있어야 합니다. 단락(short-circuit) 연산자에 대한 자세한 내용은 && 연산자|| 연산자를 참조하십시오.

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

// CS0218.cs
using System;
public class MyClass
{
   // uncomment these operator declarations to resolve this CS0218
   /*
   public static bool operator true (MyClass f)
   {
      return false;
   }

   public static bool operator false (MyClass f)
   {
      return false;
   }
   */

   public static implicit operator int(MyClass x)
   {
      return 0;
   }

   public static MyClass operator & (MyClass f1, MyClass f2)
   {
      return new MyClass();
   }

   public static void Main()
   {
      MyClass f = new MyClass();
      int i = f && f;   // CS0218, requires operators true and false
   }
}

참고 항목

참조

변환 연산자(C# 프로그래밍 가이드)