Sdílet prostřednictvím


Compilerfehler CS1618

Aktualisiert: November 2007

Fehlermeldung

Delegat mit "Methode" kann nicht erstellt werden, da er ein Conditional-Attribut enthält.
Cannot create delegate with 'method' because it has a Conditional attribute

Sie können keinen Delegaten mit einer conditional-Methode erstellen, da die Methode in einigen Builds möglicherweise nicht enthalten 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");
   }
}