英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论