HomeCSharpC# Error CS8130 – Cannot infer the type of implicitly-typed deconstruction variable ‘{0}’.

C# Error CS8130 – Cannot infer the type of implicitly-typed deconstruction variable ‘{0}’.

C# Error

CS8130 – Cannot infer the type of implicitly-typed deconstruction variable ‘{0}’.

Reason for the Error & Solution

Cannot infer the type of implicitly-typed deconstruction variable.

Example

The following sample generates CS8130:

// CS8130.cs (5,14)
class Program
{
    static void Main()
    {
        var (x2, y2) = () => { };
    }
}

The compiler cannot convert a delegate (Action) to a two-element tuple and thus is unable to infer the type of each element of the tuple.

To correct this error

To assign a value to a tuple, ensuring the right-hand-side expression is a tuple with the same number of elements as that on the left-hand-side corrects this error:

    static void Main()
    {
        var (x2, y2) = (1, 2);
    }

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