컴파일러 오류 CS0217
업데이트: 2007년 11월
오류 메시지
사용자 정의 논리 연산자('operator')를 단락(short circuit) 연산자로 사용하려면 연산자의 두 매개 변수와 같은 형식을 반환해야 합니다.
In order to be applicable as a short circuit operator a user-defined logical operator ('operator') must have the same return type as the type of its 2 parameters.
사용자 정의 형식의 연산자를 정의하여 단락 연산자로 사용하려면 사용자 정의 연산자에 매개 변수 및 같은 형식의 반환 값을 사용해야 합니다. 단락 연산자에 대한 자세한 내용은 && 연산자와 || 연산자를 참조하십시오.
다음 샘플에서는 CS0217 오류가 발생하는 경우를 보여 줍니다.
// CS0217.cs
using System;
public class MyClass
{
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 int operator & (MyClass f1, MyClass f2) // CS0217
// try the following line instead
// public static MyClass operator & (MyClass f1, MyClass f2)
{
return new MyClass();
}
public static void Main()
{
MyClass f = new MyClass();
int i = f && f;
}
}