c# - 编译C#程序时出现 "Invalid Expression Term ' .' "错误

标签 c#

因此,目前我的任务是运行由第 3 方编写的 crm 解决方案。我是一名 Java 开发人员,不太习惯 C# 开发环境。

我正在尝试重建 dll,但我不断在以下行收到 Invalid expression term '.':

investor.CustomerTypeCode = i.clientType?.code;

这显然是为了检查可为空的字段。

我认为这可能是 .net 版本问题,但尝试了一切直到 4.5。

希望有人能给我指出正确的方向

最佳答案

I thought it might be a .net version issue but tried everything till 4.5 .

您停得太早了:?. 运算符直到 C# 6 才被引入,它是 .NET 4.6 版本的一部分。

您也可以针对 .NET 4.5 及更早版本,只要您拥有正确的编译器版本(有关详细信息,请参阅 Does C# 6.0 work for .NET 4.0?)。

如果无法使用 C# 6 编译器,请按如下方式重写赋值:

investor.CustomerTypeCode = i.clientType != null ? i.clientType.code : null;

关于c# - 编译C#程序时出现 "Invalid Expression Term ' .' "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37628730/

相关文章:

c# - 什么会导致不为 UDP 数据报计算 IP header 校验和?

c# - 为什么使用 StreamWriter 在输出中没有写入任何行

c# - 如何检测应用程序是否受内存限制?

c# - 在 .NET 中使用 PEM 编码的 RSA 私钥

c# - 如何在 C# 中做标志

c# - Dictionary<string, List<string>> 的所有值都与最后输入的值相同

c# - mahapps 地铁 showMessageAsync 错误 : "Object reference not set to an instance of an object"

c# - 从定时器事件中止线程

C#检测光标是否隐藏

c# - .NET Google api 1.7 beta 使用刷新 token 进行身份验证