Lire en anglais

Partager via


Erreur du compilateur CS1594

Le délégué 'délégué' utilise des arguments non valides

Le type d’un argument passé à un appel de délégué ne correspond pas au type du paramètre dans la déclaration du délégué.

L’exemple suivant génère l’erreur CS1594 :

C#
// CS1594.cs  
using System;  
delegate string func(int i);   // declare delegate  
  
class a  
{  
   public static void Main()  
   {  
      func dt = new func(z);  
      x(dt);  
   }  
  
   public static string z(int j)  
   {  
      Console.WriteLine(j);  
      return j.ToString();  
   }  
  
   public static void x(func hello)  
   {  
      hello("8");   // CS1594  
      // try the following line instead  
      // hello(8);  
   }  
}