1

Local functions were introduced in C# 7.0 and C# 7.0 came in .NET Framework version 4.7.

I'm absolutely certain that I'm running .NET Framework 4.6.1., but I can write and use local function without issue. How can this be explained?

J. Mini
  • 1,868
  • 1
  • 9
  • 38
  • 6
    Because it's a language feature handled by the compiler and does not require special runtime support. You can use other newer constructs as well, such as out variables, binary literals, expression bodied getters and setters, etc. – György Kőszeg Jun 15 '23 at 11:22
  • That is quite well explained here https://stackoverflow.com/a/317885/7167572 – Tatranskymedved Jun 15 '23 at 11:41

1 Answers1

3

See c# language versioning. All .net framework version uses C# 7.3 by default. Even if I suspect they mean all supported .net framework versions.

All 4.* versions of .net uses the same runtime. Local functions are "syntactic suggar", and the only thing needed is a compiler that supports this feature, no runtime support is needed.

You can specify <LangVersion>latest</LangVersion> in your project file and use language features from c# 11 if you want. This is not officially supported, but works well enough for me. Just note that not all features will be available, since some features require support from the newer runtimes.

I would also consider updating to .Net 4.8, this should be fairly simple to do, and I do not think there is any supported windows build that includes 4.6.1 but not 4.8.

JonasH
  • 28,608
  • 2
  • 10
  • 23