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);
}
}