Lire en anglais

Partager via


Erreur du compilateur CS8129

Instance ou méthode d'extension « Deconstruct » appropriée introuvable pour le type avec les paramètres out et un type de retour void.

Exemple

L’exemple suivant génère l’avertissement CS8129 :

// CS8129.cs (11,52)

class C
{
    static void Main()
    {
        long x;
        string y;
        (x, y) = new C();
    }

    public int Deconstruct(out int a, out string b)
    {
        a = 1;
        b = "hello";
        return 42;
    }
}

Pour corriger cette erreur

Une méthode Deconstruct valide retourne void et a au moins deux paramètres out qui correspondent au type d’un tuple qui serait déconstruit. L’implémentation d’une méthode Deconstruct valide corrige cette erreur :

    public void Deconstruct(out int a, out string b)
    {
        a = 1;
        b = "hello";
    }