你为什么可以在.NET Framework 4.6.1中编写本地函数?

huangapple go评论52阅读模式
英文:

Why can I write local functions in .NET Framework 4.6.1.?

问题

本地函数是在C# 7.0中引入的,并且C# 7.0在.NET Framework版本4.7中发布。

我绝对确定我正在运行.NET Framework 4.6.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?

答案1

得分: 3

请参阅c#语言版本控制。所有的.NET Framework版本默认使用C# 7.3。即使我怀疑他们指的是所有支持的.NET Framework版本。

所有4.*版本的.NET都使用相同的运行时。本地函数只是“语法糖”,唯一需要的是支持此功能的编译器,不需要运行时支持。

您可以在项目文件中指定<LangVersion>latest</LangVersion>,如果需要,可以使用C# 11的语言特性。虽然官方不支持此功能,但对我来说运行得足够好。只需注意,由于某些功能需要新版本运行时的支持,因此并非所有功能都可用。

我还建议考虑升级到.NET 4.8,这应该相对简单,我认为没有任何支持的Windows版本包含4.6.1但不包含4.8。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月15日 19:16:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481915.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定