Hi, Readers.
The public preview for Dynamics 365 Business Central 2024 release wave 2 (BC25) is available. Learn more: Link.
I will continue to test and share some new features that I hope will be helpful.
Use the ternary operator when coding in the AL language:
Business value:
https://learn.microsoft.com/en-us/dynamics365/release-plan/2024wave2/smb/dynamics365-business-central/use-ternary-operator-when-coding-al-language?wt.mc_id=DX-MVP-5004336
The ternary operator? :
known from other programming languages streamlines conditional operations in code, enhances readability, and reduces verbosity. It’s particularly useful for simple conditions, promoting code clarity and intent-focused programming. By allowing variable initialization within the same line, it ensures proper assignment and minimizes code length. With this release, AL now also supports the ternary operator.
About this update first came from Steffen Balslev, Source:
Sample code:
Yes, ternary operator is finally coming to AL.
Syntax:
condition ? exprIfTrue : exprIfFalse
Let’s see more details.
The ternary operator ? :
can now be used to assign one of two values to a variable, depending on the condition of an expression.
Here’s an example of using if-then-else as until now and the new ternary operator.
Another example:
It’s particularly useful for simple conditions, promoting code clarity and intent-focused programming. Give it a try!!!😁
PS: Ternary conditional operator in wiki
Update a post from Volodymyr Dvernytskyi: The Dark Side of Ternary Operator
END
Hope this will help.
Thanks for reading.
ZHU
コメント