Hello,
I have one Boolean property in C# class (Model). and I want to check if it is NULL or not in X++ code. How can I do this ?
I tried in x++ like : classObject.property != NULL but it gives exception.
How to check for for in X++ for C# boolean type.
bool and bool? are actually very different things. Therefore you weren't right when saying that it's a Boolean property.
Try something like this in X .
System.Nullable nullableBool = classObject.Property; if (nullableBool.HasValue) { boolean value = nullableBool; } // Or simpler if (classObject.Property.HasValue) { boolean value = nullableBool; }
Let us know how it went; CLR Interop often struggles with more complicated cases and you can't be sure it work until you actually try it.
Yes. It is nullable (bool?). Right now I have changed some implementation and not able to Reproduce the exception I got. But yes it is working properly by comparing with false and also working if I write if(classObject.property) as Martin suggested below.
Thanks for the reply
It's a pity that you didn't mention what exception you got.
But if the type is boolean, comparing it with null indeed wrong. Simply use if (classObject.property), or compare it with true or false literals or a boolean expression.
Hi Pratik Rami,
Could you, please, share exception details?
Do you know if the boolean property in the C# class is nullable (bool?) or not (bool)? It could be not nullable and therefore you need to compare it with false.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Mansi Soni as our August 2025 Community…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Sohaib Cheema 708 User Group Leader
Martin Dráb 589 Most Valuable Professional
Yng Lih 553