欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在 C# 代码中确定当前的 C# 版本和 dotnet 版本

最编程 2024-06-01 10:27:25
...
using System.Reflection; using System.Runtime.InteropServices; var csharpVersion = typeof(string).Assembly .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) .OfType<AssemblyFileVersionAttribute>() .FirstOrDefault()?.Version; Console.WriteLine($"C# Language Version: {csharpVersion}"); var runtimeVersion = RuntimeInformation.FrameworkDescription; Console.WriteLine($".NET Runtime Version: {runtimeVersion}");

推荐阅读