Gerry
Gerry

Reputation: 33

Getting "Invalid Expression Term '.' " error when compiling a C# program

So currently I was tasked to run a crm solution that was written by 3rd party. I am a java dev and not so used to the c# dev environment.

I am trying to just rebuild the dll, but I keep getting Invalid expression term '.' at the following line:

investor.CustomerTypeCode = i.clientType?.code;

Which is to check for a nullable field apparently.

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

Hope someone can maybe point me in the right direction

Upvotes: 1

Views: 4127

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726569

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

You stopped too early: the ?. operator has not been introduced until C# 6, which is part of .NET 4.6 release.

You can target .NET 4.5 and earlier as well, as long as you have the right compiler version (see Does C# 6.0 work for .NET 4.0? for more details).

If using C# 6 compiler is not an option, rewrite the assignment as follows:

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

Upvotes: 3

Related Questions