C# Error CS8129 – No suitable ‘Deconstruct’ instance or extension method was found for type ‘{0}’, with {1} out parameters and a void return type.

C# Error

CS8129 – No suitable ‘Deconstruct’ instance or extension method was found for type ‘{0}’, with {1} out parameters and a void return type.

Reason for the Error & Solution

No suitable ‘Deconstruct’ instance or extension method was found for type, with out parameters and a void return type.

Example

The following sample generates 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;
    }
}

To correct this error

A valid Deconstruct method returns void and has two or more out parameters that match the type of a tuple that would be deconstructed. Implementing a valid Deconstruct method corrects this error:

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

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...