c# - C# Preprocesors 指令与(c# 版本)
问题描述
预处理器有没有办法根据 C# 的版本执行代码?例子:
#if CSharpVersion = 7.3
var value = 1;
#endif
解决方案
One option would be to define the LangVersion
explicitly in the Project file and have the constants defined based on it. For example,
<LangVersion>7.3</LangVersion>
and
<DefineConstants Condition="'$(LangVersion)' == '7.3'">DEBUG;TRACE;LANG_VERSION_7_3</DefineConstants>
<DefineConstants Condition="'$(LangVersion)' != '7.3'">DEBUG;TRACE;LANG_VERSION_NOT_7_3</DefineConstants>
Now you could use directives as
#if LANG_VERSION_7_3
Console.WriteLine("C# 7_3");
#elif LANG_VERSION_NOT_7_3
Console.WriteLine("Not C# 7_3");
#endif
Please note the LANG_VERSION
would signify the compiler accepts syntax specified version or lower.
推荐阅读
- bash - “build”关键字有什么作用?
- javascript - AngularJS工厂函数直接在初始执行时捕获块
- aws-amplify - 在放大验证器注册组件中设置默认国家代码
- ios - 为什么单视图的UIStackView,按比例填充,布局边距会导致模糊约束错误?
- c++ - C++通过builder实例化一个对象
- javascript - 基于MongoDB中Object内部数组的过滤器
- reporting-services - 有没有办法在 ssrs 中获取行的字母编号而不是数字编号?
- php - 如果有人将 / 添加到 url,则重定向
- reactjs - 来自状态的 React Ant Design defaultValue 不起作用
- html - 移动版页面不向下滚动