-1

There is a more or less recent (Jan 2020) video on YouTube explaining how to use a compound where clause in LINQ. In this example, the where is used twice, but for objects that are not related. When I try this in Visual Studio 2017 (in a Program.cs file) I get an error:

Error: Predefined type 'System.ValueTuple`2' is not defined or imported

Previously I was getting an error about the foreach clause.

The example is here: https://www.youtube.com/watch?v=uUsnDXYRADA&t=263s , and is as follows: int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; int[] numbersB = {1, 3, 5, 7, 8};

var pairs = from a in numbersA
            from b in numbersB
            where a < b
            select (a, b);

Console.WriteLine("Pairs where a < b:");
foreach (var pair in pairs)
{
    Console.WriteLine($"{pair.a} is less than {pair.b}");
}

I have VS Professional 2017, with ASP.NET Web Frameworks and Tools 5.2.6, Core Razor 15.8, C# Tools 2.10 LINQ works in the system, but this query does not.

VISQL
  • 1,960
  • 5
  • 29
  • 41

1 Answers1

1

This is not related to Linq, you are returning a Tuple type which your current version of Framework does not support it. Tuples are supported in .Net Framework 4.7+. If you upgrade your project to use a higher framework version (4.7+), the code will work.

More Information

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171