3

When I try to build a Visual Studio 2017 solution (works) using Visual Studio 2010, it gives me a syntax error on the line of code below.

var x = (from a in list where a.fld is null select a).ToList();

I've already changed that line to == null so the code compiles now on both versions of Visual Studio, but I'm interested to know why is null fails in VS2010?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Roger
  • 333
  • 2
  • 13
  • 2
    Visual Studio isn't involved at all. It's the language version that matters. In any case, the common case is to use `a.fld == null`, not `is null` – Panagiotis Kanavos Sep 06 '19 at 08:57
  • 1
    A reminder that the earliest supported .NET runtime is 4.5, which works with VS 2012 and later. You're using an unsupported VS version to target an unsupported runtime. Unless you deploy to Windows **XP** chances are the runtime will be 4.5+ and later, as 4.x updates are binary replacements of the previous versions. If you try to use VS 2010 you'll encounter many changes beyond the pattern matching syntax. – Panagiotis Kanavos Sep 06 '19 at 09:04

1 Answers1

6

The is null pattern matching syntax was introduced in C# 7 (see here).

The maximum version of the C# language supported by the Visual Studio 2010 IDE and bundled compiler seems to be C# 4 (see here).

In short: you can't do this because the version of the C# language your project is written in does not support this syntax.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86