HomeCSharpC# Error CS8132 – Cannot deconstruct a tuple of ‘{0}’ elements into ‘{1}’ variables.

C# Error CS8132 – Cannot deconstruct a tuple of ‘{0}’ elements into ‘{1}’ variables.

C# Error

CS8132 – Cannot deconstruct a tuple of ‘{0}’ elements into ‘{1}’ variables.

Reason for the Error & Solution

Cannot deconstruct a tuple of elements into variables.

Example

The following sample generates CS8132:

// CS8132.cs (5,9)
class Program
{
    static void F(object x, object y, object? z)
    {
        (object? a, object? b) = (x, y, z = 3);
        Console.WriteLine(a);
        Console.WriteLine(b);
        Console.WriteLine(z);
    }
}

To correct this error

To deconstruct to a tuple with a smaller number of elements, using the discard variables will correct this error:

class Program
{
    static void F(object x, object y, object? z)
    {
        (object? a, object? b, object _) = (x, y, z = 3);
        Console.WriteLine(a);
        Console.WriteLine(b);
        Console.WriteLine(z);
    }
}

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...