Compilerfehler CS1618

Es kann kein Delegat mit 'methode' erstellt werden, da sie das Attribut 'Conditional' aufweist

Sie können keinen Delegaten mit einer bedingten Methode erstellen, da die Methode in einigen Builds möglicherweise nicht vorhanden ist.

Im folgenden Beispiel wird CS1618 generiert:

// CS1618.cs  
using System;  
using System.Diagnostics;  
  
delegate void del();  
  
class MakeAnError {  
   public static void Main() {  
      del d = new del(ConditionalMethod);   // CS1618  
      // Invalid because on builds where DEBUG is not set,
      // there will be no "ConditionalMethod".  
   }  
   // To fix the error, remove the next line:  
   [Conditional("DEBUG")]  
   public static void ConditionalMethod()
   {  
      Console.WriteLine("Do something only in debug");  
   }  
}