web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to check C# Boolean Property is Null or not in X++ code ?

(0) ShareShare
ReportReport
Posted on by 225

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.

I have the same question (0)
  • Martin Dráb Profile Picture
    235,838 Most Valuable Professional on at
    RE: How to check C# Boolean Property is Null or not in X++ code ?

    bool and bool? are actually very different things. Therefore you weren't right when saying that it's a Boolean property.

    • bool is a primitive data data (System.Boolean).
    • bool? is a generic structure (System.Nullable<System.Boolean>).

    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.

  • Pratik Rami Profile Picture
    225 on at
    RE: How to check C# Boolean Property is Null or not in X++ code ?

    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

  • Verified answer
    Martin Dráb Profile Picture
    235,838 Most Valuable Professional on at
    RE: How to check C# Boolean Property is Null or not in X++ code ?

    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.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: How to check C# Boolean Property is Null or not in X++ code ?

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 708 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 589 Most Valuable Professional

#3
Yng Lih Profile Picture

Yng Lih 553

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans