NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Compiler Error CS0218

The type ('type') must contain declarations of operator true and operator false

If you define an operator for a user-defined type, and then try to use the operator as a short-circuit operator, the user-defined operator must have operator true and operator false defined. For more information on short-circuit operators, see && Operator and || Operator.

The following sample generates CS0218:

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
   }
}